为何第三个点会RE?

P1603 斯诺登的密码

LoR_Zhong @ 2022-10-29 13:21:40

本地第三个点可以成功运行,然而洛谷上就 RE,不是很懂。

第三个点数据:\texttt{Chen Junao is no so clever .}

#include<bits/stdc++.h>
using namespace std;
map<string,int> f;
char sum[6][3];
char ans[20];
int main(){
    f["zero"]     =0;
    f["one"]      =1;
    f["two"]      =2;
    f["three"]    =3;
    f["four"]     =4;
    f["five"]     =5;
    f["six"]      =6;
    f["seven"]    =7;
    f["eight"]    =8;
    f["nine"]     =9;
    f["ten"]      =10;
    f["eleven"]   =11;
    f["twelve"]   =12;
    f["thirteen"] =13;
    f["fourteen"] =14;
    f["fifteen"]  =15;
    f["sixteen"]  =16;
    f["seventeen"]=17;
    f["eighteen"] =18;
    f["ninteen"]  =19;
    f["twenty"]   =20;

    f["a"]        =1;
    f["another"]  =1;
    f["first"]    =1;
    f["both"]     =2;
    f["second"]   =2;
    f["third"]    =3;

    string k;
    map<string,int>::iterator it;
    for(int i=0;i<6;i++){
        cin>>k;
        it=f.find(k);
        if(it==f.end()) sum[i][0]='0',sum[i][1]='0',sum[i][2]='\0';
        else sprintf(sum[i],"%02d",f[k.c_str()]*f[k.c_str()]%100);
    }
    cin>>k;
    for(int i=0;i<6;i++){
        for(int j=0;j<i;j++){
            if(strcmp(sum[j],sum[i])>0) swap(sum[j],sum[i]);
        }
    }
    for(int i=0;i<6;i++){
        strcat(ans,sum[i]);
    }
    int p=0;
    while(ans[p]=='0'||ans[p]=='\0') p++;
    if(p>=12){
        cout<<0;
        return 0;
    }
    for(int i=p;i<12;i++)
        cout<<ans[i];
}

by Smithespics @ 2023-03-09 15:44:05

个人感觉你的代码查找还是有点慢,你可以看看我的,也是通过打表做的。蒟蒻不敢说话


#include<algorithm>
#include<map>
#include<string>
using namespace std;
int arr[100];
int main()
{
    map<string,int> q;
    q["one"]=1;
    q["two"]=2;
    q["three"]=3;
    q["four"]=4;
    q["five"]=5;
    q["six"]=6;
    q["seven"]=7;
    q["eight"]=8;
    q["nine"]=9;
    q["ten"]=10;
    q["eleven"]=11;
    q["twelve"]=12;
    q["thirteen"]=13;
    q["fourteen"]=14;
    q["fifteen"]=15;
    q["sixteen"]=16;
    q["seventeen"]=17;
    q["eighteen"]=18;
    q["nineteen"]=19;
    q["twenty"]=20;
    q["a"]=1;
    q["both"]=2;
    q["another"]=1;
    q["first"]=1;
    q["second"]=2;
    q["third"]=3;

    int flag = 0;
    string str;
    while(cin >> str)
    {
        if(q[str])
        {
            if(q[str]*q[str]%100 != 0)
            {
                arr[flag++] = (q[str]*q[str])%100;
            }
        }
    }

    if(flag)
    {
        sort(arr,arr+flag-1);
        cout << arr[0];
        for(int i = 1;i < flag;i++)
        {
            if(arr[i] >= 10)
                cout << arr[i];
            else
                cout << 0 << arr[i];
        }
    }
    else
        cout << 0;

    return 0;
}

|