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:这组数据都过了还是WA 谁帮忙看看In Reply To:这组数据都过了 应该就可以过了 Posted by:gengyit at 2007-05-27 13:57:46 #include<iostream> #include<string> using namespace std; int get(string str); string str1[]={"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 str2[]={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,100,1000,1000000}; int main() { int n=4; int sign; while(n--)//问题出在这里吧? { int sum=0,hsum=0,tsum=0,msum=0; while(1)//输入多个单词 { string str; cin>>str; if(str=="negative") sign=-1; else sign=1; if(str=="hundred") { hsum=sum*100; sum=0; } else if(str=="thousand") { tsum=(hsum+sum)*1000; hsum = 0; sum=0; } else if(str=="million") { msum=(hsum+tsum+sum)*1000000; hsum=tsum=0; sum=0; } else { sum+=get(str); } if(getchar()=='\n')break; } sum+=(hsum+tsum+msum); cout<<(sign)*(sum)<<endl; } return 0; } int get(string str)//翻译 { int i; for(i=0;i<31;i++) if(str==str1[i]) break; return str2[i]; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator