【求助】为何全WA,但自己给的输入都对

P1914 小书童——凯撒密码

AmosZhou @ 2023-07-21 15:43:52

代码如下:

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    char s;
    scanf("%d\n",&n);
    while(1){
        s = getchar();
        if (s=='\n') break;
        else putchar((s-'a'+n)%26+'a');
    }
    return 0;
}

by CcmCyh11140810 @ 2023-07-21 15:55:31

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,la,b[200];
    char a[200];
    cin>>n;
    cin>>a;
    la=strlen(a);
    for(i=0;i<la;i++)
    {
        b[i]=a[i];
    }
    for(i=0;i<la;i++)
    {
        b[i]=b[i]+n;
    }
    for(i=0;i<la;i++)
    {
        if(b[i]>122)
        {
            b[i]=b[i]%122+96;
        }
    }
    for(int i=0;i<la;i++)
    {
        a[i]=b[i];
        cout<<a[i];
    }
}

这是我的


by Zz__Cc @ 2023-07-21 15:57:38

为啥我试你的代码是TLE?


by Zz__Cc @ 2023-07-21 15:58:48

@AmosZhou 建议用字符串写


by CcmCyh11140810 @ 2023-07-21 15:59:18

你这不是WA是TLE啊


by CcmCyh11140810 @ 2023-07-21 16:00:50

不过字符串长度50应该不会TLE啊


by 1000YMH @ 2023-07-30 11:57:32

求加入


by 1000YMH @ 2023-07-30 11:57:57


#include<bits/stdc++.h>
int n,a,b,c[34],d[8]; 
using namespace std;
int main(){
    cin>>n;
    for(int i=1;i<=7;i++){
        cin>>b;
        c[b]=1; 
    }
    for(int i=1;i<=n;i++){
        int sx=0;
        for(int j=1;j<=7;j++){ 
            cin>>a;
            if(c[a]==1)sx++;
        } 
        d[7-sx+1]++;
    } 
    for(int i=1;i<=7;i++)cout<<d[i]<<" ";
    return 0;
}

by Gcc_Gdb_7_8_1 @ 2023-08-08 11:38:34

建议用do-while


|