为什么只有80分啊啊啊啊啊!

P1603 斯诺登的密码

Colythme @ 2015-06-30 11:57:47

[codec]

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
long long c=0,thing[6]={0},sum=0;
int readchar(string a)
{
    if(a=="one" || a=="a" || a=="another" || a=="first"){thing[c]=1;c++;}
    else if(a=="two" || a=="both" || a=="second"){thing[c]=4;c++;}
       else if(a=="three" || a=="third"){thing[c]=9;c++;}
       else if(a=="four"){thing[c]=16;c++;}
    else if(a=="five"){thing[c]=25;c++;}
    else if(a=="six"){thing[c]=36;c++;}
    else if(a=="seven"){thing[c]=49;c++;}
    else if(a=="eight"){thing[c]=64;c++;}
    else if(a=="nine"){thing[c]=81;c++;}
    else if(a=="eleven"){thing[c]=21;c++;}
    else if(a=="twelve"){thing[c]=44;c++;}
    else if(a=="thirteen"){thing[c]=69;c++;}
    else if(a=="forteen"){thing[c]=96;c++;}
    else if(a=="fifteen"){thing[c]=25;c++;}
    else if(a=="sixteen"){thing[c]=56;c++;}
    else if(a=="seventeen"){thing[c]=89;c++;}
    else if(a=="eighteen"){thing[c]=24;c++;}
    else if(a=="nineteen"){thing[c]=61;c++;}
}
int main()
{
    string c2[6];
     for(int i=0;i<6;i++) cin>>c2[i];
     for(int i=0;i<6;i++)
     {
        if(c2[i][c2[i].size()-1]=='.') c2[i].erase(c2[i].size()-1,1);
        readchar(c2[i]); 
    }
    sort(thing,thing+c);
    for(int i=0;i<c;i++)      
    {      
        sum+=thing[i];
        sum*=100;
    }      
    printf("%d",sum/100); 
    return 0;
}

[/codec] 大神求解!


by yyy2015c01 @ 2015-06-30 15:01:49

sum是long long 类型,而你44行是%d。

第四个点是one two three four five six.

你应该是溢出了,试试nineteen nineteen nineteen nineteen nineteen nineteen.

正解为:616161616161


by fcoaxt @ 2015-07-12 23:07:41

大力枚举很不错的尝试[delete]其实我也是这么干的= =[/delete]


|