飘啊飘 @ 2019-12-05 09:04:31
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
char a[80];
cin>>n;
cin.get();
cin.getline(a,sizeof(a));
int len=strlen(a);
for(int i=0;i<len;i++){
if(a[i]+n<='z'&&a[i]+n>='a')
a[i]=a[i]+n;
else if(a[i]+n>'z')
a[i]=a[i]+n-26;
cout<<a[i];}
return 0;
}
by Sophon @ 2019-12-05 12:05:09
@飘啊飘 已AC
#include <iostream>
#include <cstring>
using namespace std;
int main() {
int n;
char a[80];
cin >> n >> a;
int len = strlen(a);
for (int i = 0; i < len; i++) {
n %= 26;
if (a[i] + n <= 'z' && a[i] + n >= 'a')
a[i] = a[i] + n;
else if (a[i] + n > 'z')
a[i] = a[i] + n - 26;
cout << a[i];
}
return 0;
}
by 飘啊飘 @ 2019-12-05 14:55:12
@Sophon
Thank you very much!
I have a question which I want to ask you
为什么输入不能用
cin.get();
cin.getline(a,sizeof(a));
?????
by laeey02048 @ 2019-12-05 17:41:00
@飘啊飘 按照系统的角度来说,只能有2个输入 而你有3个输入,所以出错了。 两个都用cin>>输入吧。
by Sophon @ 2019-12-05 17:57:52
@飘啊飘
用cin.get()也行,但是要两次
cin >> n;
cin.get();
cin.get();
cin.getline(a, sizeof(a));
这是因为生成的数据中每行末尾除了回车符以外还有一个换行符,用cin可以掠过这两个空白继续读入
by Sophon @ 2019-12-05 18:02:52
@飘啊飘 好像是这样,笑~(不过改了之后可以AC是肯定的)
by 飘啊飘 @ 2019-12-05 19:51:20
谢谢各位大佬的帮助
Thanks
by 蛇皮猪 @ 2019-12-12 20:18:45
@飘啊飘 俺和你的输入一毛一样,刚要交,幸好看了这帖子。。。
by 飘啊飘 @ 2019-12-12 20:42:50
@蛇皮猪 不用感谢