SRM 147 DIV2 250
A-Zで構成され、アルファベット順でN文字横にずらした文字列(ex.N=2:A=>C,B=>D)が与えられるので元の文字列を求めよという問題
#include <string> #include <vector> #include <sstream> using namespace std; class CCipher { public: string decode(string cipherText, int shift) { stringstream decoded; int n = 'Z' - 'A' + 1; int m = shift % n; for (int i=0; i<cipherText.length(); i++) { char c = cipherText[i] - m; if (c < 'A') { c = c + n; } decoded << c; } return decoded.str(); } };