我这个代码发生啥了?蒟蒻在线坐等

P1914 小书童——凯撒密码

希望更丰富的展现? 使用markdown
by wxx2004 @ 2019-04-21 22:40:04


~~都9102年了还有人不用markdown~~
by Koakuma @ 2019-04-21 22:41:36


``` #include<cstring> #include<iostream> #include<cstdio> using namespace std; int main() { int n; char a[100]; scanf("%d%s",&n,a); for(int i=0; i<strlen(a); i++) { a[i]=a[i]+n; if((a[i]-96)==0)printf("%c",122); else printf("%c",(a[i]-96)%26+96); } return 0; } ```
by Koakuma @ 2019-04-21 22:44:58


### ascii最多为127,再大了就会报错,之后减下去也没用 #include<iostream> #include<cstring> using namespace std; char s[9990091]; //char数组会舒服点 int main() { int n; scanf("%d%s",&n,&s); for(int i=0;i<strlen(s);i++) { if(s[i]+n>122)s[i]=s[i]+n-26; //先判断是不是加炸了 else s[i]+=n; } printf("%s",s); return 0; }
by KGB1331 @ 2019-06-15 17:30:57


**忘了加cstdio,见谅**
by KGB1331 @ 2019-06-15 17:31:15


|