Study hard
(c++)백준 11655번: ROT13 본문
https://www.acmicpc.net/problem/11655
11655번: ROT13
첫째 줄에 알파벳 대문자, 소문자, 공백, 숫자로만 이루어진 문자열 S가 주어진다. S의 길이는 100을 넘지 않는다.
www.acmicpc.net
[풀이]
ASCII코드표를 참고하여 알파벳 범위를 넘었을 때만 잘 처리해주면 된다.
#include <iostream>
#include <string>
using namespace std;
string str;
void solution() {
getline(cin, str);
for (int i = 0; i < str.size(); i++) {
//알파벳이면
if ((str[i] >= 65 && str[i] <= 90) || (str[i] >= 97 && str[i] <= 122)) {
char ch = str[i] + 13;
//소문자인데, +13이 알파벳 범위를 벗어나면
if (str[i] + 13 > 90 && str[i] <= 90)
ch = 'A' + (str[i] + 13) % 91;
//대문자인데, +13이 알파벳 범위를 벗어나면
else if (str[i] + 13 > 122)
ch = 'a' + (str[i] + 13) % 123;
str[i] = ch;
}
}
for (int i = 0; i < str.size(); i++) {
cout << str[i];
}
}
int main() {
solution();
return 0;
}
'백준 > 여러가지 문제들' 카테고리의 다른 글
(c++)백준 11656번: 접미사 배열 (0) | 2020.06.13 |
---|---|
(c++)백준 10824번: 네 수 (0) | 2020.06.13 |
(c++)백준 10820번: 문자열 분석 (0) | 2020.06.12 |
(c++)백준 10809번: 알파벳 찾기 (0) | 2020.06.12 |
(c++)백준 10808번: 알파벳 개수 (0) | 2020.06.12 |