문제 링크입니다: https://www.acmicpc.net/problem/9322
9322번: 철벽 보안 알고리즘
문제 소희는 공개키와 개인키 한 쌍으로 보안을 유지하는 것이 매우 불편하다고 생각했다. 그래서 소희는 공개키와 개인키를 암호화 체계를 개발했다. 이를 "철벽 보안 알고리즘"이라고 부르기로 했다. 알고리즘은 다음과 같다. 한 단어는 1~10개의 대문자(A-Z)들로 이루어진 문자열이다. 한 문장은 공백으로 구분된 단어들로 이루어졌다. 제 1 공개키는 최대 한 번만 사용된 단어들로 되어있다. 제 2 공개키는 제 1 공개키의 단어들을 재배치하여 만들어진다. 평문
www.acmicpc.net
생각보다 머리를 써야하는 문제였습니다.
자료구조는 map과 vector를 사용했습니다.
기본적인 로직은 map을 이용하여 제1 공개키와 제2 공개키의 순서 상관관계를 파악하고 이 정보를 기반으로 암호문을 올바른 순서로 출력하는 과정입니다.
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 <iostream> | |
#include <map> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int T; | |
cin >> T; | |
for (int t = 0; t < T; t++) | |
{ | |
int n; | |
cin >> n; | |
map<string, int> firstPublicKey; | |
for (int i = 0; i < n; i++) | |
{ | |
string key; | |
cin >> key; | |
firstPublicKey[key] = i; | |
} | |
map<int, int> orders; | |
for (int i = 0; i < n; i++) | |
{ | |
string key; | |
cin >> key; | |
orders[firstPublicKey[key]] = i; | |
} | |
vector<string> password(n); | |
for (int i = 0; i < n; i++) | |
{ | |
cin >> password[i]; | |
} | |
for (int i = 0; i < n; i++) | |
{ | |
cout << password[orders[i]] << " "; | |
} | |
cout << "\n"; | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 2108번 통계학 (0) | 2020.02.24 |
---|---|
백준 11375번 열혈강호 (0) | 2020.02.23 |
백준 16673번 고려대학교에는 공식 와인이 있다 (0) | 2020.02.18 |
백준 14395번 4연산 (0) | 2020.02.17 |
백준 2941번 크로아티아 알파벳 (0) | 2020.02.16 |