Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4885 | Accepted: 1905 |
Description
Input
Output
Sample Input
six negative seven hundred twenty nine one million one hundred one eight hundred fourteen thousand twenty two
Sample Output
6 -729 1000101 814022
Source
/* *Copyright (c)2015,烟台大学计算机与控制工程学院 *All rights reserved. *作 者:单昕昕 *完成日期:2015年8月22日 *版 本 号:v1.0 */ #include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { char s[100],c; int sum=0,ans=0,flag; while(cin>>s) { if(strcmp(s,"negative")==0)flag=1; else if(strcmp(s,"zero")==0)sum+=0; else if(strcmp(s,"one")==0)sum+=1; else if(strcmp(s,"two")==0)sum+=2; else if(strcmp(s,"three")==0)sum+=3; else if(strcmp(s,"four")==0)sum+=4; else if(strcmp(s,"five")==0)sum+=5; else if(strcmp(s,"six")==0)sum+=6; else if(strcmp(s,"seven")==0)sum+=7; else if(strcmp(s,"eight")==0)sum+=8; else if(strcmp(s,"nine")==0)sum+=9; else if(strcmp(s,"ten")==0)sum+=10; else if(strcmp(s,"eleven")==0)sum+=11; else if(strcmp(s,"twelve")==0)sum+=12; else if(strcmp(s,"thirteen")==0)sum+=13; else if(strcmp(s,"fourteen")==0)sum+=14; else if(strcmp(s,"fifteen")==0)sum+=15; else if(strcmp(s,"sixteen")==0)sum+=16; else if(strcmp(s,"seventeen")==0)sum+=17; else if(strcmp(s,"eighteen")==0)sum+=18; else if(strcmp(s,"nineteen")==0)sum+=19; else if(strcmp(s,"twenty")==0)sum+=20; else if(strcmp(s,"thirty")==0)sum+=30; else if(strcmp(s,"forty")==0)sum+=40; else if(strcmp(s,"fifty")==0)sum+=50; else if(strcmp(s,"sixty")==0)sum+=60; else if(strcmp(s,"seventy")==0)sum+=70; else if(strcmp(s,"eighty")==0)sum+=80; else if(strcmp(s,"ninety")==0)sum+=90; else if(strcmp(s,"hundred")==0)sum*=100; else if(strcmp(s,"thousand")==0) { ans+=sum*1000; sum=0; } else if(strcmp(s,"million")==0) { ans+=sum*1000000; sum=0; } if((c=getchar())=='\n') { if(flag==1) cout<<-(ans+sum)<<endl; else cout<<ans+sum<<endl; sum=ans=flag=0; } } return 0; }