9322 철벽 보안 알고리즘
2019. 8. 23. 11:36ㆍ알고리즘/백준
총 3개의 정보가 주어지는데, 공개키 2개와 암호문이다. 암호문을 평문으로 바꾸는 것은 공개키2가 공개키1로 가는 규칙을 따르면 된다
첫 예제를 보면, 다음과 같다
A B C D - 제 1공개키
D A B C - 제 2공개키
C B A P - 암호문
공개키2에서 공개키1로 가는 규칙은 0번 인덱스의 D가 3번으로 갔으니 0번은 3번으로 보낸다. 그리고 마찬가지로 A를 살펴보면 1번은 0번으로 보내고, 이러한 규칙을 암호문에 적용을 시키면
B A P C로 결과가 나오게 된다
문제: https://www.acmicpc.net/problem/9322
깃허브주소: https://github.com/surinoel/boj/blob/master/9322.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <map> | |
#include <string> | |
#include <vector> | |
#include <iostream> | |
using namespace std; | |
int changeidx[1000]; | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int tc; | |
cin >> tc; | |
while (tc--) { | |
int n; | |
cin >> n; | |
string s; | |
map<string, int> minfo; | |
for (int i = 0; i < n; i++) { | |
cin >> s; | |
minfo[s] = i; | |
} | |
for (int i = 0; i < n; i++) { | |
cin >> s; | |
changeidx[i] = minfo[s]; | |
} | |
vector<string> vs(n); | |
for (int i = 0; i < n; i++) { | |
cin >> s; | |
vs[changeidx[i]] = s; | |
} | |
for (int i = 0; i < n; i++) { | |
cout << vs[i] << ' '; | |
} | |
cout << '\n'; | |
} | |
return 0; | |
} |
'알고리즘 > 백준' 카테고리의 다른 글
3474 교수가 된 현우 (0) | 2019.08.24 |
---|---|
10040 투표 (0) | 2019.08.23 |
2823 유턴 싫어 (0) | 2019.08.21 |
9207 페그 솔리테어 (0) | 2019.08.20 |
3197 백조의 호수 (0) | 2019.08.19 |