3DE3 @ 2023-11-02 11:12:03
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
int i,len,n;//为什么不能用double型?
cin>>n>>s;
len=s.size();
for(i=0;s[i]!='\0';i++)
{
if(n>'z'-s[i])
s[i]='a'+(n-('z'-s[i]))%26-1;
else
s[i]+=n;
}
cout<<s;
return 0;
by Addrian @ 2023-11-02 12:07:34
double不能取余
by yuanshen362 @ 2023-11-02 12:34:11
其实你这么写思路有点乱。你直接用这个模
示例:
for(int i=0;i<s.length();i++)
cout<<char(((s[i]-'a')+n)%26+'a');
by yuanshen362 @ 2023-11-02 12:35:29
这么写思路清晰了,我测了一遍全部