※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 6841번 문제인 I Speak TXTMSG이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/6841
6841번: I Speak TXTMSG
The user will be prompted to enter text to be translated one line at a time. When the short form “TTYL” is entered, the program ends. Users may enter text that is found in the translation table, or they may enter other words. All entered text will be s
www.acmicpc.net
입력으로 주어지는 각 문자열에 대하여 문제에 주어진 변역표에 존재한다면 번역된 문자열을, 그렇지 않다면 원형 그대로의 문자열을 출력해 문제를 해결하자. 이는 map을 이용해 간편하게 구현할 수 있다. map을 사용하지 않더라도 조건문을 이용해 구현할 수도 있다.
'와 ’는 다른 문자임에 유의하자. (예제 출력 참고)
아래는 제출한 소스코드이다.
#include <iostream>
#include <string>
#include <map>
using namespace std;
map<string, string> mp;
string s;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
mp.insert(make_pair("CU", "see you"));
mp.insert(make_pair(":-)", "I’m happy"));
mp.insert(make_pair(":-(", "I’m unhappy"));
mp.insert(make_pair(";-)", "wink"));
mp.insert(make_pair(":-P", "stick out my tongue"));
mp.insert(make_pair("(~.~)", "sleepy"));
mp.insert(make_pair("TA", "totally awesome"));
mp.insert(make_pair("CCC", "Canadian Computing Competition"));
mp.insert(make_pair("CUZ", "because"));
mp.insert(make_pair("TY", "thank-you"));
mp.insert(make_pair("YW", "you’re welcome"));
mp.insert(make_pair("TTYL", "talk to you later"));
while (getline(cin, s)) {
if (mp.count(s)) cout << mp[s] << '\n';
else cout << s << '\n';
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 2756 // C++] 다트 (1) | 2022.12.17 |
---|---|
[BOJ 2758 // C++] 로또 (0) | 2022.12.17 |
[BOJ 26332 // C++] Buying in Bulk (1) | 2022.12.17 |
[BOJ 6840 // C++] Who is in the middle? (0) | 2022.12.17 |
[BOJ 26340 // C++] Fold the Paper Nicely (1) | 2022.12.17 |