[백준/BOJ] 백준 1599번 : 민식어
2022. 2. 6. 17:11ㆍ알고리즘 문제풀이
https://www.acmicpc.net/problem/1599
1599번: 민식어
첫째 줄에 민식어 단어의 개수 N이 주어진다. N은 50보다 작거나 같은 자연수이다. 둘째 줄부터 한 줄에 하나씩 단어가 입력으로 들어온다. 단어의 길이는 최대 50자이다. 민식어에 없는 알파벳이
www.acmicpc.net
입력받은 민식어 단어를, 순서에 매치되는 알파벳 단어로 만들고, 알파벳 단어로 만들어진 단어들을 정렬한 뒤, 다시 순서에 매치되는 민식어로 바꾸어 문제를 해결했다
코드
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
int n;
vector<string> makeds;
vector<string> inputs;
map<string, string> m_to_a;
map<string, string> a_to_m;
void Pre()
{
//순서 비교를 위해 영어 알파벳 순서를 저장
//민식어,영어
m_to_a = { {"a", "a"},{"b","b"},{"k","c"},{"d","d"},{"e","e"},{"g","f"},
{"h","g"},{"i","h"},{"l","i"},{"m","j"},{"n","k"},{"ng","l"},{"o","m"},{"p","n"},
{"r","o"},{"s","p"},{"t","q"},{"u","r"},{"w","s"},{"y","t"} };
//영어, 민식어
a_to_m = { {"a","a"},{"b","b"},{"c","k"},{"d","d"},{"e","e"},{"f","g"},
{"g","h"},{"h","i"},{"i","l"},{"j","m"},{"k","n"},{"l","ng"},{"m","o"},{"n","p"},
{"o","r"},{"p","s"},{"q","t"},{"r","u"},{"s","w"},{"t","y"} };
}
int main()
{
cin.tie(NULL);
ios_base::sync_with_stdio(false);
Pre();
cin >> n;
for (int i = 0; i < n; i++)
{
string input;
cin >> input;
string maked = "";
for (int j = 0; j < input.size(); j++)
{
if (j < input.size() - 1)
{
if (input.substr(j, 2) == "ng")
{
maked += m_to_a["ng"];
j++;
continue;
}
}
maked += m_to_a[input.substr(j, 1)];
}
makeds.push_back(maked);
}
//영어 순서로 정렬
sort(makeds.begin(), makeds.end());
for (int i = 0; i < n; i++)
{
string maked = makeds[i];
string input = "";
for (int j = 0; j < maked.size(); j++)
{
input += a_to_m[maked.substr(j, 1)];
}
cout << input << "\n";
}
return 0;
}
'알고리즘 문제풀이' 카테고리의 다른 글
[백준/BOJ] 백준 16347번 : Alloc (0) | 2022.02.07 |
---|---|
[백준/BOJ] 백준 12880번 : 그래프 차이 최소 (0) | 2022.02.06 |
[백준/BOJ] 백준 13505번 : 두 수 XOR (0) | 2022.02.06 |
[백준/BOJ] 백준 2661번 : 좋은수열 (0) | 2022.02.06 |
[백준/BOJ] 백준 2437번 : 저울 (0) | 2022.02.06 |