dp_hater @ 2022-06-18 14:33:15
这....devc++运行的跟样例一样,可是......
代码见下:
#include<bits/stdc++.h>
using namespace std;
char a[10000];
int main(){
int n;
cin>>n;
cin.ignore();
cin.getline(a,51);
for(int i=0;i<strlen(a);i++){
cout<<(char)((int)(a[i]-'a'+n)%26+'a');
}
cout<<endl;
return 0;
}
by lixuhui20120805 @ 2022-08-09 14:39:37
#include<bits/stdc++.h>
using namespace std;
string s;
int n;
int main(int argc, char** argv) {
cin >> n >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 'a' && s[i] <= 'z') {//26个字母循环一次
int rest =n%26;
int cur = (int) s[i] + rest;
if (cur > 'z') {//偏移的结果超过了字母z,需要从a从新开始偏移
int gap = cur - 'z';//计算超过了z多少个数量
s[i]=gap+'a'-1;//从'a'开始偏移
} else {
s[i] += rest;
}
}
}
cout << s;
return 0;
}
AC