为什么第四个点错了????

P1603 斯诺登的密码

wanghai673 @ 2017-01-25 15:57:49

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
string n[21]={" ","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"};
string m[10]={" ","a","both"};
string t[4]={" ","first","second","third"};
int b[1001],k=1;
int main()
{
//freopen("C:\\Documents and Settings\\Administrator\\桌面\\新建 文本文档.txt","r",stdin);
    string a;
    getline(cin,a);
    int len=a.size();
    for(int i=0;i<len;++i)if(a[i]>='A'&&a[i]<='Z')a[i]=a[i]-'A'+'a';
    char *p=&a[0];
    for(int i=0;i<=len;++i)
    {
        if(a[i]==' '||a[i]=='\0')
        {
            a[i]='\0';
            for(int j=1;j<=20;++j)
            {
                if(strcmp(p,n[j].c_str())==0)
                {
                    b[k++]=(j*j)%100;
                    break;
                }
            }
            for(int j=1;j<=6;++j)
            {
                if(strcmp(p,m[j].c_str())==0)
                {
                    b[k++]=(j*j)%100;
                    break;
                }
            }
            for(int j=1;j<=3;++j)
            {
                if(strcmp(p,t[j].c_str())==0)
                {
                    b[k++]=(j*j)%100;
                    break;
                }
            }
            if(strcmp(p,"another")==0)b[k++]=1;
            p=&a[i]+1;
        }
    }
    sort(b+1,b+k+1);
    int sum=0;
    for(int i=1;i<=k;++i)
    {
        sum+=b[i];
        sum*=100;    
    }
    cout<<sum/100;
    return 0;
}

by dayangxx @ 2017-01-31 18:15:07

sum 要用long long, 用int会超。附上第四个测试点:

输入:

one two three four five six .

输出:

10409162536

我也被卡了


by jxsdxxf @ 2017-02-12 12:50:02

直接排序后输出啊(小于10特判),为什么还要拼接成一个整数???


|