7-14 凯撒密码 (10 分)
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
string s;
int offset;
int main()
{
getline(cin, s, '\n');
cin >> offset;
offset %= 26;
// cout << s << ' ' << offset << endl;
for (int i=0; i<s.size(); i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
int p = s[i] - 'a';
p = ((p + offset) + 26) % 26;
cout << (char) ('a' + p);
} else if (s[i] >= 'A' && s[i] <= 'Z') {
int p = s[i] - 'A';
p = ((p + offset) + 26) % 26;
cout << (char) ('A' + p);
} else cout << s[i];
}
return 0;
}
7-14 凯撒密码 (10 分)
最新推荐文章于 2022-11-16 20:42:07 发布