[백준 13288] A New Alphabet (C#, C++) - soo:bak
작성일 :
문제 링크
설명
문장 속 영문자를 정해진 새 알파벳 규칙으로 바꾸고 나머지는 그대로 출력하는 문제입니다.
접근법
먼저 알파벳 소문자에 대한 치환표를 준비합니다.
다음으로 문자열을 한 글자씩 보면서 알파벳이면 대응 문자열로 바꿉니다.
이후 알파벳이 아닌 문자는 그대로 유지합니다.
마지막으로 변환된 결과를 출력합니다.
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
using System;
using System.Text;
class Program {
static void Main() {
var map = new[] {
"@", "8", "(", "|)", "3", "#", "6", "[-]", "|", "_|", "|<", "1",
"[]\\/[]", "[]\\[]", "0", "|D", "(,)", "|Z", "$", "']['", "|_|", "\\/",
"\\/\\/", "}{", "`/", "2"
};
var s = Console.ReadLine()!;
var sb = new StringBuilder();
for (var i = 0; i < s.Length; i++) {
var c = s[i];
if (c >= 'A' && c <= 'Z') c = (char)(c + 32);
if (c >= 'a' && c <= 'z') sb.Append(map[c - 'a']);
else sb.Append(c);
}
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
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
vector<string> map = {
"@", "8", "(", "|)", "3", "#", "6", "[-]", "|", "_|", "|<", "1",
"[]\\/[]", "[]\\[]", "0", "|D", "(,)", "|Z", "$", "']['", "|_|", "\\/",
"\\/\\/", "}{", "`/", "2"
};
string s;
getline(cin, s);
string out;
out.reserve(s.size());
for (char c : s) {
if (c >= 'A' && c <= 'Z') c = char(c + 32);
if (c >= 'a' && c <= 'z') out += map[c - 'a'];
else out += c;
}
cout << out << "\n";
return 0;
}