| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
WA到无语,高手帮忙看下呗!#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int ans,flag,lev[10],tmp[10],i,j,s,t,tag;
char c[10],ch;
void fun(){
int temp;
if(!strcmp(c,"negative"))flag=1;
else if(!strcmp(c,"zero")){tag=1;tmp[s++]=0;}
else if(!strcmp(c,"one")){tag=1;tmp[s++]=1;}
else if(!strcmp(c,"two")){tag=1;tmp[s++]=2;}
else if(!strcmp(c,"three")){tag=1;tmp[s++]=3;}
else if(!strcmp(c,"four")){tag=1;tmp[s++]=4;}
else if(!strcmp(c,"five")){tag=1;tmp[s++]=5;}
else if(!strcmp(c,"six")){tag=1;tmp[s++]=6;}
else if(!strcmp(c,"seven")){tag=1;tmp[s++]=7;}
else if(!strcmp(c,"eight")){tag=1;tmp[s++]=8;}
else if(!strcmp(c,"nine")){tag=1;tmp[s++]=9;}
else if(!strcmp(c,"ten")){tag=1;tmp[s++]=10;}
else if(!strcmp(c,"eleven")){tag=1;tmp[s++]=11;}
else if(!strcmp(c,"twelve")){tag=1;tmp[s++]=12;}
else if(!strcmp(c,"thirteen")){tag=1;tmp[s++]=13;}
else if(!strcmp(c,"fourteen")){tag=1;tmp[s++]=14;}
else if(!strcmp(c,"fifteen")){tag=1;tmp[s++]=15;}
else if(!strcmp(c,"sixteen")){tag=1;tmp[s++]=16;}
else if(!strcmp(c,"seventeen")){tag=1;tmp[s++]=17;}
else if(!strcmp(c,"eighteen")){tag=1;tmp[s++]=18;}
else if(!strcmp(c,"nineteen")){tag=1;tmp[s++]=19;}
else if(!strcmp(c,"twenty")){tag=0;tmp[s++]=2;lev[t++]=10;}
else if(!strcmp(c,"thirty")){tag=0;tmp[s++]=3;lev[t++]=10;}
else if(!strcmp(c,"forty")){tag=0;tmp[s++]=4;lev[t++]=10;}
else if(!strcmp(c,"fifty")){tag=0;tmp[s++]=5;lev[t++]=10;}
else if(!strcmp(c,"sixty")){tag=0;tmp[s++]=6;lev[t++]=10;}
else if(!strcmp(c,"seventy")){tag=0;tmp[s++]=7;lev[t++]=10;}
else if(!strcmp(c,"eighty")){tag=0;tmp[s++]=8;lev[t++]=10;}
else if(!strcmp(c,"ninety")){tag=0;tmp[s++]=9;lev[t++]=10;}
else if(!strcmp(c,"hundred"))
if(tag){lev[t++]=100;tag=0;}
else{
temp=0;
for(j=0;j<t;j++)
if(tmp[j]&&lev[j]<100){
temp+=tmp[j]*lev[j];
tmp[j]=0;
}
tmp[t-1]=temp;
lev[t-1]=100;
}
else if(!strcmp(c,"thousand"))
if(tag){lev[t++]=1000;tag=0;}
else{
temp=0;
for(j=0;j<t;j++)
if(tmp[j]&&lev[j]<1000){
temp+=tmp[j]*lev[j];
tmp[j]=0;
}
tmp[t-1]=temp;
lev[t-1]=1000;
}
else if(!strcmp(c,"million"))
if(tag){lev[t++]=1000000;tag=0;}
else{
temp=0;
for(j=0;j<t;j++)
if(tmp[j]&&lev[j]<1000000){
temp+=tmp[j]*lev[j];
tmp[j]=0;
}
tmp[t-1]=temp;
lev[t-1]=1000000;
}
}
int main()
{
while(scanf("%c",&ch)&&ch!='\n'&&ch!=' '){
flag=0;s=t=0;
while(ch!='\n'){
i=0;
while(ch!=' '&&ch!='\n'){
c[i++]=ch;
ch=getchar();
}
c[i]='\0';
fun();
if(ch==' ')ch=getchar();
}
while(t<s)lev[t++]=1;
ans=0;
for(i=1;i<s;i++)
if(lev[i]>lev[i-1])
for(j=0;j<i;j++)
if(tmp[j]&&lev[j]<lev[i]){
tmp[i]+=tmp[j]*lev[j];
tmp[j]=0;
}
for(i=0;i<s;i++)
ans+=tmp[i]*lev[i];
if(flag)putchar('-');
printf("%d\n",ans);
}
system("PAUSE");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator