hw20王文浩 @ 2021-07-04 20:47:03
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string a,b;
cin>>a;
int k=a.length();
for(int i=0;i<=k;i++){
if(a[i]>=97&&a[i]<=122-n) b[i]=a[i]+n;
else b[i]=a[i]+n-26;
}
for(int i=0;i<=k;i++) cout<<b[i];
return 0;
}
by 来福 @ 2021-07-17 18:24:12
我擦,我们思路一模一样,我也错了
by 来福 @ 2021-07-17 18:38:23
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,i=0;
char str[100];
cin>>n;
// char c;
// c = getchar();这个不知道为啥不对
scanf("\r");
gets(str);
while(str[i]!='\0'){
if('z'-n>=str[i]&&'a'<=str[i])
str[i]=str[i]+n;
else{
str[i]=str[i]+n-26;
}
i++;
}
puts(str);
return 0;
}
by linhanyu @ 2021-07-22 12:46:21
@yunfree getchar()只能读入一个字符
by 来福 @ 2021-07-22 21:09:50
@linhanyu 嗯,对谢谢了,读入数据有毛病,还和把cpp和c的输入函数混用也有点关系