※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 8385번 문제인 ROT13이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/8385
8385번: ROT13
The Byteland Aircraft Factory has recently developed a new type of jet plane. Naming the planes with numbers is not fashionable anymore, so the management decided to form a two-word name. To draw potential clients' attention, the name should have an additi
www.acmicpc.net
주어지는 문자열의 집합의 원소 중 그 문자열의 ROT13 또한 집합에 들어있는 원소의 수를 (중복없이) 구하는 문제이다.
set 자료구조를 이용해 중복없이 문자열들을 다뤄 문제를 해결해주자.
아래는 제출한 소스코드이다.
#include <iostream>
#include <string>
#include <set>
using namespace std;
int N, slen;
char rot13[128];
set<string> st1, st2;
int ans;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (char i = 'a'; i < 'n'; i++) rot13[i] = i + 13;
for (char i = 'n'; i <= 'z'; i++) rot13[i] = i - 13;
cin >> N;
while (N--) {
string s;
cin >> s;
if (s[0] < 'n') st1.insert(s);
else st2.insert(s);
}
for (auto x:st1){
for (auto& l:x) l = rot13[l];
if (st2.count(x)) ans += 2;
}
cout << ans;
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 6123 // C++] Oh Those Fads (1) | 2024.02.10 |
---|---|
[BOJ 29130 // C++] Стеллаж с книгами (0) | 2024.02.09 |
[BOJ 8598 // C++] Zając (1) | 2024.02.07 |
[BOJ 8673 // C++] Krany (0) | 2024.02.06 |
[BOJ 6005 // C++] Cow Pinball (1) | 2024.02.05 |