11655.ROT13
by 브이담곰
11655번: ROT13
첫째 줄에 알파벳 대문자, 소문자, 공백, 숫자로만 이루어진 문자열 S가 주어진다. S의 길이는 100을 넘지 않는다.
www.acmicpc.net
✔ 유형 : 구현
✔ 문제 풀이 : 아스키 코드를 이용한 간단한 구현
⬇ 코드 보기
더보기
// Online C++ compiler to run C++ program online #include <bits/stdc++.h> using namespace std; int main() { string sentence; string result; getline(cin, sentence); //공백 포함 string 입력 받기 // 조건 : 소문자, 대문자가 아닌 문자는 그대로 남아 있어야 한다. for(auto word : sentence) { int ascii = int(word); int shift = ascii + 13; if(ascii >= 65 && ascii <= 90) // 대문자 혹은 소문자 일 경우 13칸 미뤄준다. { result += char(shift > 90 ? shift - 26 : shift ); } else if(ascii >= 97 && ascii <= 122) { result += char(shift > 122 ? shift - 26 : shift ); } else { result += word; } } cout << result; return 0; }
블로그의 정보
농담곰담곰이의곰담농
브이담곰