题解 | 密码翻译
密码翻译
https://www.nowcoder.com/practice/136de4a719954361a8e9e41c8c4ad855
#include <iostream>
#include <string>
using namespace std;
//设计一个统一的加密函数
char Encrypt(char a){
if(a>='a'&&a<='y' || a>='A'&&a<='Y') return ++a;
else if(a=='z') return 'a';
else if(a=='Z') return 'A';
else return a;
}
int main() {
string str;
while(getline(cin,str)){ //读入整行数据,使用getline
for(char &i:str){
i=Encrypt(i);
}
cout<<str<<'\n';
}
return 0;
}

查看3道真题和解析