http://bailian.openjudge.cn/practice/2767/
#include<iostream> #include <cmath> #include <math.h> #include <vector> #include <algorithm> #include <map> #include <string> //#include <string.h> #include <unordered_map> int main() { std::map<int, char> m; std::unordered_map<char, int> um; for (int i = 0; i < 26; i++) { m.emplace(i, 'A' + i); um.emplace('A' + i, i); } /*for (auto temp : um) { std::cout << temp.first << " " << temp.second << std::endl; }*/ std::string input; //cin会捕捉空格 //std::cin >> input; getline(std::cin, input); for (int i = 0; i < input.size(); i++) { auto umit = um.find(input[i]); if (umit != um.end()) { int num = (*umit).second; //加上26防止-号 int correct = (num - 5 + 26) % 26; std::cout << m[correct]; } else { std::cout << input[i]; } } }