백준(C++)/0000_부수적인 문제들
[BOJ/C++]11655번_ROT13
코잼민
2024. 7. 20. 13:49
https://www.acmicpc.net/problem/11655
##풀이 :
1_ <예제 입력 1 >분석
2_ 따라서, 어떤 문자는 "+13"이 되고, 어떤 문자가 "-13"이 되는지 기준을 찾으려 함
3_ 핵심 포인트 :
'A'>= 문자 <='L' || 'a'>= 문자 <= 'l' 범위 의 문자 (그룹 ①) => +13
: 'N'>= 문자 <='Z' || 'n'>= 문자 <= 'z' 범위 의 문자 (그룹 ②) => -13
## 코드 :
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
30
31
32
33
34
35
36
|
#include <iostream>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string text;
getline(cin, text, '\n');
for (int i = 0; i < text.length(); i++) {
if (isalpha(text[i])) {//알파벳이라면,
if (//그룹 ①
(text[i] >= 'A' && text[i] < 'N')
||
(text[i] >= 'a' && text[i] < 'n')
)
{
text[i] += 13;
}
else {//그룹 ②
text[i] -= 13;
}
}
}
cout << text<<'\n';
return 0;
}
|
cs |