C++)
#include <iostream>
#include <string>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int k, s;
string st;
cin >> k >> s;
cin.ignore();
getline(cin, st);
k %= 26;
for (auto ch : st) {
if (isupper(ch))
cout << char((ch - 'A' + k) % 26 + 'A');
else if (islower(ch))
cout << char((ch - 'a' + k) % 26 + 'a');
else
cout << ch;
}
return 0;
}
Python)
import sys
read = sys.stdin.readline
k, s = map(int, read().rstrip().split())
k %= 26
st = read().rstrip()
ans = []
for ch in st:
if ch.isupper():
ans.append(chr((ord(ch) - ord('A') + k) % 26 + ord('A')))
elif ch.islower():
ans.append(chr((ord(ch) - ord('a') + k) % 26 + ord('a')))
else:
ans.append(ch)
print(''.join(ans))'백준 1 > 기타' 카테고리의 다른 글
| [백준 1920] 수 찾기 (C++) (0) | 2020.12.06 |
|---|---|
| [백준 11651] 좌표 정렬하기 - 2 (C++) (0) | 2020.12.06 |
| [백준 11650] 좌표 정렬하기 (C++) (0) | 2020.12.06 |
| [백준 16360] Go Latin (C++) (0) | 2020.12.06 |
| [백준 10988] 팰린드롬인지 확인하기 (C++/Python) (0) | 2020.12.06 |