简答
2026-09-09 21:05:46
发布于:湖南
11阅读
0回复
0点赞
题目是凯撒密码解密:密文是大写字母,密文往前挪 5 位就是明文。
比如密文 A,往前数 5 个字母,A 前面没有了,就要从 Z 往回绕。
不是字母的字符,原样不动直接输出。
那肯定是这样写吧
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
getline(cin,s);
for(int i=0;i<s.size();i++){
if(s[i]<'A'||s[i]>'Z'){
cout<<s[i];
continue;
}
if(s[i]-5<'A'){
cout<<char('Z'+s[i]-'A'-5+1);
}else{
cout<<char(s[i]-5);
}
}
return 0;
}。
呵呵,那你可能错了
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
getline(cin, s);
for(char c : s){
if(c >= 'A' && c <= 'Z'){
int num = c - 'A';
num = (num - 5 + 26) % 26;
cout << (char)(num + 'A');
}else{
cout << c;
}
}
return 0;
}
嗯,没错,这下就对了,嗯,总之来说题目并不简单。
这里空空如也








有帮助,赞一个