/*
Time:2019.11.8
Author: Goven
type:模拟(字母替换)
err:
ref:
*/
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main()
{
map<char, char> mp;
for (char c = 'A'; c <= 'Z'; c++) {
mp[c] = 'A' + (c - 'A' - 5 + 26) % 26;
}
string str;
while (getline(cin, str) && str != "ENDOFINPUT") {
while (getline(cin, str) && str != "END") {
int l = str.length();
for (int i = 0; i < l; i++) {
if (str[i] >= 'A' && str[i] <= 'Z') {
cout << mp[str[i]];
}
else cout << str[i];
}
cout << endl;
}
}
return 0;
}
//更简单的写法:https://blog.csdn.net/qq_36258516/article/details/70877479
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main(){
string a = "VWXYZABCDEFGHIJKLMNOPQRSTU";
string str;
while (getline(cin, str)) {
if (str == "ENDOFINPUT") break;
if (str == "START" || str == "END") continue;
for (int i = 0; i < str.length(); i++) {
if (str[i] >= 'A' && str[i] <= 'Z') {
str[i] = a[str[i] - 'A'];
}
}
cout << str << endl;
}
}
网友评论