模拟题,
提交时,要支持iostream同时使用long long则应选g++.
Source:
#include<iostream>
#include<string>
using namespace std;
char word[220]="negative,zero,one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen,twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety,hundred,thousand,million";
int val[220];
int main()
{
char str[20],ch;
long long res,f,p,c;
val[9]=0;val[14]=1;val[18]=2;val[22]=3;val[28]=4;val[33]=5;
val[38]=6;val[42]=7;val[48]=8;val[54]=9;val[59]=10;val[63]=11;
val[70]=12;val[77]=13;val[86]=14;val[95]=15;val[103]=16;val[111]=17;
val[121]=18;val[130]=19;val[139]=20;val[146]=30;val[153]=40;val[159]=50;
val[165]=60;val[171]=70;val[179]=80;val[186]=90;val[193]=100;val[201]=1000;val[210]=1000000;
res=0;f=1;c=0;
while(cin>>str)
{
// cout<<str<<endl;
p=strstr(word,str)-word;
if(p==0)f=-1;
else if(val[p]<100)
{
c+=val[p];
}else if(val[p]==100)
{
if(c==0)res*=100;
else c*=100;
}else
{
if(c==0)res*=val[p];
else res+=c*val[p];
c=0;
}
// cout<<res<<":"<<c<<endl;
ch=cin.get();
if(ch=='/n')
{
cout<<(res+c)*f<<endl;
res=0;f=1;c=0;
}
}
return 0;
}