[백준 23738] Ресторан (C#, C++) - soo:bak
작성일 :
문제 링크
설명
주어진 대문자 문자열을 러시아어 알파벳 발음 규칙에 따라 소문자 문자열로 변환하는 문제입니다.
접근법
각 문자에 대해 대응되는 발음을 문자열로 치환해 이어 붙이면 됩니다.
한 글자가 두 글자로 바뀌는 경우(예: E→ye)는 그대로 추가합니다.
Code
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System;
using System.Text;
class Program {
static void Main() {
var s = Console.ReadLine()!;
var sb = new StringBuilder();
foreach (var c in s) {
if (c == 'A') sb.Append("a");
else if (c == 'B') sb.Append("v");
else if (c == 'E') sb.Append("ye");
else if (c == 'K') sb.Append("k");
else if (c == 'M') sb.Append("m");
else if (c == 'H') sb.Append("n");
else if (c == 'O') sb.Append("o");
else if (c == 'P') sb.Append("r");
else if (c == 'C') sb.Append("s");
else if (c == 'T') sb.Append("t");
else if (c == 'Y') sb.Append("u");
else sb.Append("h");
}
Console.WriteLine(sb.ToString());
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s; cin >> s;
string res;
for (char c : s) {
if (c == 'A') res += "a";
else if (c == 'B') res += "v";
else if (c == 'E') res += "ye";
else if (c == 'K') res += "k";
else if (c == 'M') res += "m";
else if (c == 'H') res += "n";
else if (c == 'O') res += "o";
else if (c == 'P') res += "r";
else if (c == 'C') res += "s";
else if (c == 'T') res += "t";
else if (c == 'Y') res += "u";
else res += "h";
}
cout << res << "\n";
return 0;
}