pku2121

模拟题,

提交时,要支持iostream同时使用long long则应选g++.

Source:

#include<iostream>

#include<string>

using namespace std;

 

char word[220]="negative,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 val[220];

 

int main()

{

    char str[20],ch;

    long long res,f,p,c;

   

    val[9]=0;val[14]=1;val[18]=2;val[22]=3;val[28]=4;val[33]=5;

    val[38]=6;val[42]=7;val[48]=8;val[54]=9;val[59]=10;val[63]=11;

    val[70]=12;val[77]=13;val[86]=14;val[95]=15;val[103]=16;val[111]=17;

    val[121]=18;val[130]=19;val[139]=20;val[146]=30;val[153]=40;val[159]=50;

    val[165]=60;val[171]=70;val[179]=80;val[186]=90;val[193]=100;val[201]=1000;val[210]=1000000;

 

    res=0;f=1;c=0;

    while(cin>>str)

    {

//     cout<<str<<endl;

       p=strstr(word,str)-word;

       if(p==0)f=-1;

       else if(val[p]<100)

       {  

           c+=val[p];

       }else if(val[p]==100)

       {

           if(c==0)res*=100;

           else c*=100;

       }else

       {

           if(c==0)res*=val[p];

           else res+=c*val[p];

           c=0;

       }

//     cout<<res<<":"<<c<<endl;

       ch=cin.get();

       if(ch=='/n')

       {

           cout<<(res+c)*f<<endl;

           res=0;f=1;c=0;

       }

    }

    return 0;

}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值