카테고리 없음
백준 2149번 암호 해독 C++
영춘권의달인
2023. 4. 13. 14:42
https://www.acmicpc.net/problem/2149
2149번: 암호 해독
어떤 문장을 키를 이용하여 다음과 같이 암호화하려 한다. 암호화하기 전의 문장을 평문이라 하며, 암호화 된 문장은 암호문이라고 한다. 키, 평문, 암호문은 모두 영어 대문자로 된 공백 없는
www.acmicpc.net
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
string key, code;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> key >> code;
map<pair<char, int>, vector<char>> mp;
for (int i = 0; i < key.length(); i++) {
vector<char> v;
mp.insert({ {key[i],i},v });
}
auto it = mp.begin();
int len = code.length() / key.length();
for (int i = 0; i < key.length(); i++) {
for (int j = i * len; j < (i + 1) * len; j++) {
it->second.push_back(code[j]);
}
++it;
}
for (int i = 0; i < len; i++) {
bool print = false;
for (int j = 0; j < key.length(); j++) {
for (auto a : mp) {
if (a.first.second == j) cout << a.second[i];
}
}
}
}