Mr_Ender @ 2020-03-07 20:21:14
#include<iostream>
using namespace std;
int main(){
string vol,loc;
int i,vol1[105],key;
cin>>key>>vol;
for(i=0;i<vol.length();i++){
vol1[i]=vol[i];
loc[i]=(vol1[i]+key-96)%26+96;
}
for(i=0;i<=vol.length();i++){
cout<<loc[i];
}
return 0;
}
by liqingyang @ 2020-03-07 20:21:32
让我看看
by liqingyang @ 2020-03-07 20:23:22
@Mr_Ender 有几个问题:
string要包含头文件(string)(建议)
数组切记不要定义在main里面!
by liqingyang @ 2020-03-07 20:24:46
还有,直接loc[i]=(vol[i]+key-96)%26+96;
by liqingyang @ 2020-03-07 20:26:16
还有为什么不直接输出呢?
by liqingyang @ 2020-03-07 20:26:43
例如直接cout<<char((vol[i]+key-96)%26+96);
by liqingyang @ 2020-03-07 20:28:31
代码(帮你改的,把voi改成str了):
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
int key;
cin>>key>>str;
for(int i=0;i<str.size();i++)
{
cout<<char((str[i]+key-'a')%26+'a');
}
cout<<endl;
return 0;
}
by Mr_Ender @ 2020-03-08 09:09:43
懂了,十分感谢