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 |
是否遗忘了strtok ?#include<map> #include<string> #include<iostream> using namespace std; char* s[]={"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 k[]={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 i,neg,tem,ans; char* p,buf[999]; map<string,int> M; int main(){ for(i=0;i<31;i++) M[s[i]]=k[i]; for(;gets(buf)&&*buf;){ ans=0; p=strtok(buf," "); neg=string(p)=="negative"?-1:1; tem=string(p)=="negative"?0:M[p]; for(;p=strtok(0," ");){ if(M[p]<99) tem+=M[p]; else { tem*=M[p]; if(100<M[p]){ ans+=tem; tem=0; } } } cout<<neg*(ans+tem)<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator