0017 - Caesar Cipher / AizuOnlineJudge
問題 : シーザー暗号 | Aizu Online Judge
#include <algorithm> #include <iostream> #include <string> using namespace std; void Solve(string str) { for (int i=0; i<26; ++i) { for (int j=0; j<str.length(); ++j) if ('a'<=str[j] && str[j]<='z') if (++str[j] > 'z') str[j]='a'; if (str.find("that") != string::npos) break; else if (str.find("the") != string::npos) break; else if (str.find("this") != string::npos) break; } cout << str << endl; } int main(void) { string str; while ( getline(cin,str) ) Solve(str); return 0; }
文字列の全ての文字を1文字ずつ先に進め、
"that", "the", "this"という文字列が現れたら文字列を出力する。
~了~