解题思路:
加密时:
1. 反转
2. 大小写转换
3. 循环左移3位
则解密时:
1. 反转
2. 大小写转换
3. 循环右移3位
注意事项:
参考代码:
#include <iostream> // #include <sstream> // #include <cstdio> #include <algorithm> // #include <cmath> // #include <cstdlib> // #include <cstring> #include <cctype> // #include <string> // #include <climits> // #include <map> // #include <vector> // #include <list> // #include <set> using namespace std; // const int maxn = 40004; // const long long MOD = 100000007; // const double PI = acos(-1.0); int main() { /* input */ string s; cin >> s; /* decode 1. reverse 2. upper to lower, lower to upper 3. 'A'+3 -> 'D', 'Z'+3->'C' */ reverse(s.begin(), s.end()); for (int i = 0; i < s.size(); i++) { if (isupper(s[i])) s[i] = tolower(s[i]); else s[i] = toupper(s[i]); s[i] += 3; if ( !isalpha(s[i]) ) s[i] -= 26; } /* output */ cout << s << endl; return 0; }
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题8.3 (Java代码)浏览:1374 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:698 |
时间转换 (Java代码)浏览:576 |
【明明的随机数】 (C++代码)浏览:781 |
简单的a+b (C语言代码)浏览:531 |
淘淘的名单 (C语言代码)浏览:1104 |
WU-图形输出 (C++代码)浏览:802 |
WU-拆分位数 (C++代码)浏览:788 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:594 |
哥德巴赫曾猜测 (C语言代码)浏览:2352 |