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 |
Re:咱也来贴一个短代码啦 \(^o^)/~In Reply To:咱也来贴一个短代码啦 \(^o^)/~ Posted by:1010321112 at 2011-09-07 00:59:00 > 之前错了几次,后来加上(LEN=strlen(w))!=0就AC了,不容易啊 > > Source Code > > Problem: 2121 User: 1010321112 > Memory: 172K Time: 16MS > Language: C++ Result: Accepted > > Source Code > #include<iostream> > using namespace std; > #include<string.h> > int main() > { > int a[3],LEN,len,m,i,k; > long sum; > char w[300],s[10]; > char word[28][10]={"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"}; > int num[28]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 > ,17,18,19,20,30,40,50,60,70,80,90}; > while(gets(w),(LEN=strlen(w))!=0) > { > sum=m=0; > a[0]=a[1]=a[2]=0; > sscanf(w,"%s",s); > while(1) > { > if(!strcmp(s,"negative")) > putchar('-'); > else if(!strcmp(s,"million")) > a[m++]*=1000000; > else if(!strcmp(s,"thousand")) > a[m++]*=1000; > else if(!strcmp(s,"hundred")) > a[m]*=100; > else > for(i=0;i<28;i++) > if(!strcmp(s,word[i])) > { a[m]+=num[i]; break; } > len=strlen(s); > sum+=len+1; > sscanf(w,"%*s%s",s); > if(sum>=LEN) break; > w[sum-1]='A'; ///将空格变为字母 > } > sum=a[0]+a[1]+a[2]; > printf("%d\n",sum); > } > return 0; > } 这个怎么会对,one thousand one million应该是1001000000才对呀,可是跑出来不是,,, Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator