Give me the number 数字单词转数字 (模拟)

本文介绍了一种将英文描述的大于0且小于10^9的整数转换为其对应的阿拉伯数字的方法。通过使用映射表将英文单词与数值对应,并采用字符串处理技巧逐词解析输入的英文数字。

Give me the number

Time Limit:1000MS  Memory Limit:65536K
Total Submit:  Accepted:  

Description

在英文里面,数字是以下面所给的方式写出来的(现只考虑小于10^9 的数字)。 数字 abc,def,ghi 记作 "[abc] million [def] thousand [ghi]"。这里 "[xyz] " 表示三位数xyz

如果abc = 0 ,那么 "[abc] million" 被省略,如果def = 0 ,那么 "[def] thousand" 也被省略,如果ghi = 0 ,那么 "[ghi] " 也被省略。如果整个数就是0,那么记作 "zero"。注意到,就算有多于一个的“million”或多于一个的“thousand”,单词 "million" "thousand" 都是单数形式。


小于一千的数字是采用下面的方式表示。数字 xyz 记作 "[x] hundred and [yz] ”( 如果 yz = 0 ,那么它就是 “[x] hundred”。否则,如果 y = 0 ,就应记作 “[x] hundred and [z]”) 如果x = 0 "[x] hundred and" 被省略。注意到 "hundred" 也是单数形式。


20
以下的数字记作 "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen" 以及 "nineteen"


20
99 之间的数字用下面的方法表示。数字 xy 记作 "[x0] [y] ", 其中的二十九十相应记作 "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", and "ninety"


例如,数字987,654,312记作
"nine hundred and eighty seven million six hundred and fifty four thousand three hundred and twelve"
数字100,000,037记作 "one hundred million thirty seven" 数字1,000 记作 "one thousand"


注意到:对于百万、千、百来说 "one" 是不会被省略的。

给出用英文表示的数字,请写出相应的阿拉伯数字形式的整数。

Input

有多个测试用例。输入的第一行是一个整数 T (1 <= T <= 1900) ,表示测试用例的个数。接下来是T 个测试用例。
每个测试用例占一行,是一串表示一个数字的英文单词。

Output

对应每行输入的英文数字,输出相应的阿拉伯数字整数,单独一行。假设所有整数都少于109

Sample Input

4
one
eleven
one hundred and two
two hundred million seven hundred and one thousand two hundred and ten

Sample Output

1
11
102
200701210

代码加解题思路如下:

 

#include<iostream>

#include<string>

#include<map>

using namespace std;

string str,temp;

map<string,int> m;      //强大的map

//char m[][20]={,m["one",m["two",m["three",m["four",m["five",m["six",m["seven",m["eight",m["nine",m["ten",m["eleven",m["twelve",m["thirteen",m["fourteen",m["fifteen",m["sixteen",m["seventeen",m["eighteen",m["nineteen","twenty",m["thirty",m["forty",m["fifty",m["sixty",m["seventy",m["eighty",m["ninety",m["hundred",m["thousand",m["",m["billion"};

int main()

{

//     freopen("E://data.in", "r", stdin);

       m["zero"]=0;

       m["one"]=1;

       m["two"]=2;

       m["three"]=3;

       m["four"]=4;

       m["five"]=5;

       m["six"]=6;

       m["seven"]=7;

       m["eight"]=8;

       m["nine"]=9;

       m["ten"]=10;

       m["eleven"]=11;

       m["twelve"]=12;

       m["thirteen"]=13;

       m["fourteen"]=14;

       m["fifteen"]=15;

       m["sixteen"]=16;

       m["seventeen"]=17;

       m["eighteen"]=18;

       m["nineteen"]=19;

       m["twenty"]=20;

       m["thirty"]=30;

       m["forty"]=40;

       m["fifty"]=50;

       m["sixty"]=60;

       m["seventy"]=70;

       m["eighty"]=80;

       m["ninety"]=90;

       m["hundred"]=100;

       m["thousand"]=1000;

       m["million"]=1000000;

       m["and"]=0;                  //打得好烦啊,打到后来才想起可以用offic工具。。。Orz

       int cases;

       int num;

       int p;

       int i;

       int len;

       int sum;

       scanf("%d",&cases);

       getchar();

       while(cases--)

       {

              getline(cin,str);     //string好像怎么用都不会太长的=_=

              str=str+' ';               //开始是想每个单词处理一次的,后来发现不会,应该是用sscanf()吧,但偷懒了

              str=' '+str;  //发现这样每个单词就是“temp ”了

              num=0;

              p=1;

              sum=0;

              len=str.length();

              for(i=1;i<len;i++)

              {

                     if(str[i]==' ')

                     {

                      temp=str.substr(p,i-p);  //p开始长度为i-p的串,最开始记成是beginend了。555,记住,string.substr第二个参数是长度!!

                            p=i+1;

                            if(m[temp]>100)

                            {

                                   num*=m[temp];

                                   sum+=num;

                                   num=0;

                            }

                            else if(m[temp]==100)      //100很牛B!!

                            {

                                   num*=100;

                            }

                            else

                                   num+=m[temp];

                     }

              }

              sum+=num;

              printf("%d/n",sum);

       }

       return 0;

}

这是一道crypto题目,背景是二战期间,在布莱切利园工作的你主要负责破译轴心国的电子密文。一天下午,你成功截获了一段加密信号并记录了下来: 1.信号在接收到第六个“5”后有明显的电流声,可能是对前面密文的补充 提示是本涉及的编码(区别编码和加密)方式仅为Base64和Hex.flag形式为flag{&times;&times;&times;&times;&times;}(保留空格,全部小写) 给了一个文本,是626e52324947647065475a766458427162793132626e6c30625770796247677572dc9f843ec35f46a3b6003c95ad011ae6b8e12e5e2c2df2e3e2b92321a0b59cd5e6e4bbdb6e3222024b91b2c0c5ee678f928e41babed98cc26b855645605342a483e0b761c42db1bc04843a7a73dcaba515efdd67247ef18ddede4da32a4f097703e16f848e10b0a94edc9dcda0676890701c931fcb96335c9f7cf4fe2d757190d859bb8804d28d978d740f9f3c13aa44dbcc5ca1cbbfabfc332952b2112680eaef54ecc6f668f9d70f63a7229c9d8284b88ebef1cd3c42fa3c5274549729712c880c509ce86975689370f7081200481945b188b4bc7150a4a3a7bec9d8b798684b775daf4c0fcf1534bdd948bb13c1 其中第六个5之后的72dc9f843ec35f46a3b6003c95ad011ae6b8e12e5e2c2df2e3e2b92321a0b59cd5e6e4bbdb6e3222024b91b2c0c5ee678f928e41babed98cc26b855645605342a483e0b761c42db1bc04843a7a73dcaba515efdd67247ef18ddede4da32a4f097703e16f848e10b0a94edc9dcda0676890701c931fcb96335c9f7cf4fe2d757190d859bb8804d28d978d740f9f3c13aa44dbcc5ca1cbbfabfc332952b2112680eaef54ecc6f668f9d70f63a7229c9d8284b88ebef1cd3c42fa3c5274549729712c880c509ce86975689370f7081200481945b188b4bc7150a4a3a7bec9d8b798684b775daf4c0fcf1534bdd948bb13c1 题目提供给我KEY和IV我通过cbc解出来内容是The number of models is the same as that of Tesla's midsize sedan models. Damn it, the order of the letters (A-F) is the same as the CET options. 我该怎么得到flag?
最新发布
10-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值