Give Me the Number


Time Limit: 2 Seconds      Memory Limit: 65536 KB

Numbers in English are written down in the following way (only numbers less than 109 are considered). Number abc,def,ghi is written as "[abc] million [def] thousand [ghi]". Here "[xyz]" means the written down number xyz .

In the written down number the part "[abc] million" is omitted if abc = 0 , "[def] thousand" is omitted if def = 0 , and "[ghi] " is omitted if ghi = 0 . If the whole number is equal to 0 it is written down as "zero". Note that words "million" and "thousand" are singular even if the number of millions or thousands respectively is greater than one.

Numbers under one thousand are written down in the following way. The number xyz is written as "[x] hundred and [yz] ”. ( If yz = 0 it should be only “[x] hundred”. Otherwise if y = 0 it should be only “[x] hundred and [z]”.) Here "[x] hundred and" is omitted if x = 0 . Note that "hundred" is also always singular.

Numbers under 20 are written down as "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", and "nineteen" respectively. Numbers from 20 to 99 are written down in the following way. Number xy is written as "[x0] [y] ", and numbers divisible by ten are written as "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", and "ninety" respectively.

For example, number 987,654,312 is written down as "nine hundred and eighty seven million six hundred and fifty four thousand three hundred and twelve", number 100,000,037 as "one hundred million thirty seven", number 1,000 as "one thousand". Note that "one" is never omitted for millions, thousands and hundreds.

Give you the written down words of a number, please give out the original number.

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 1900) which is the number of test cases. It will be followed by T consecutive test cases.

Each test case contains only one line consisting of a sequence of English words representing a number.

Output

For each line of the English words output the corresponding integer in a single line. You can assume that the integer is smaller than 109.

Sample Input

3
one
eleven
one hundred and two

Sample Output

1
11
102

Author: CAO, Peng
Source: The 5th Zhejiang Provincial Collegiate Programming Contest

#include <iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
map<string,int> mp;
char ch[],str[];
int t,ans,num;
int main()
{ mp.clear();
mp["zero"]=; mp["one"]=;
mp["two"]=; mp["three"]=;mp["four"]=;
mp["five"]=;mp["six"]=;mp["seven"]=; mp["eight"]=;
mp["nine"]=;mp["ten"]=; mp["eleven"]=;
mp["twelve"]=;mp["thirteen"]=; mp["fourteen"]=;
mp["fifteen"]=; mp["sixteen"]=; mp["seventeen"]=;
mp["eighteen"]=;mp["nineteen"]=;
mp["twenty"]=; mp["thirty"]=; mp["forty"]=;
mp["fifty"]=; mp["sixty"]=; mp["seventy"]=;
mp["eighty"]=; mp["ninety"]=; while(~scanf("%d",&t))
{
getchar();
for(;t>;t--)
{
gets(ch);
//getchar();
int len=strlen(ch),l=-;
ch[len]=' '; len++;
memset(str,,);
ans=; num=;
for(int i=;i<len;i++)
{
if (ch[i]!=' ') str[++l]=ch[i];
else
{
if (mp.find(str)!=mp.end()) num+=mp[str];
else
{
if (strcmp(str,"million")==)
{num=num*; ans+=num; num=;}
if (strcmp(str,"thousand")==)
{num=num*; ans+=num; num=;}
if (strcmp(str,"hundred")==)
num=num*;
}
//str[]='';
memset(str,,);//把字符串数组清空的神奇方法
l=-;
} }
printf("%d\n",ans+num);
}
}
return ;
}

ZOJ 2971 Give Me the Number (模拟,字符数组的清空+map)的更多相关文章

  1. ZOJ 2971 Give Me the Number;ZOJ 2311 Inglish-Number Translator (字符处理,防空行,strstr)

    ZOJ 2971 Give Me the Number 题目 ZOJ 2311 Inglish-Number Translator 题目 //两者题目差不多,细节有点点不一样,因为不是一起做的,所以处 ...

  2. ZOJ 2971 Give Me the Number

    Give Me the Number Numbers in English are written down in the following way (only numbers less than  ...

  3. HDU 1711 Number Sequence (字符串匹配,KMP算法)

    HDU 1711 Number Sequence (字符串匹配,KMP算法) Description Given two sequences of numbers : a1, a2, ...... , ...

  4. C语言博客作业—字符数组

    一.PTA实验作业 题目1:字符串转换成十进制整数 1. 本题PTA提交列表 2. 设计思路 (1)定义i为循环变量,number用于存放每一次转化的结果,flag用于判断是否为负数,p用于修改结果的 ...

  5. C语言---字符数组

    一.PTA实验作业 题目1:7-2 统计一行文本的单词个数 1. 本题PTA提交列表 2. 设计思路 定义循环变量i,j定义不为空格的字符数count,定义单词数number,i,j,count,nu ...

  6. Java-IO之CharArrayWriter(字符数组输出流)

    CharArrayWriter用于写数据,数据单位是字符. (1) 通过CharArrayWriter()创建的CharArrayWriter对应的字符数组大小是32. (2) 通过CharArray ...

  7. Codeforces Round #369 (Div. 2) A. Bus to Udayland【字符串/二维字符数组求连起来的座位并改为其他字符】

    A. Bus to Udayland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. C语言中的字符数组和字符串

    在C语言中,没有字符串类型,但是可以通过字符数组来模拟字符串. 字符串可以在栈上,堆上,静态区和常量区进行分配. char buf[50]  = "abc"; char buf[] ...

  9. Java 学习(6):java Number & Math & String & 数组...常用类型

    目录 --- Number & Math类 --- Character 类 --- String 类 --- StringBuffer 类 --- 数组 Number & Math类: ...

随机推荐

  1. JSM 学习(一)

    JMS 支持两类消息传送模型:点对点模型和发布/订阅模型.又称这些消息传送模型为消息传送域.点对点模型和发布订阅模型分别缩写为p2p和Pub/Sub.发布订阅模型用于一对多消息广播,点对点模型用于一对 ...

  2. Struts2.5.12中动态方法调用问题

    使用版本:struts-2.5.12-all 出现问题:在开启动态方法调用后,找不到没有匹配的路径映射 <constant name="struts.enable.DynamicMet ...

  3. Lucene.Net 3.0.3如何从TokenStream中获取token对象

    Lucene.Net最高版本为3.0.3,并且apache已经不再提供Lucene.Net的更新,没仔细研究过Lucene.Net的所有版本,Lucene.Net3.0.3遍历TokenStream获 ...

  4. SQL Server 对XML数据类型的SQL语句总结

    --创建XMLTable , ) primary key, XMLCol xml); go ------------------------------------------------------ ...

  5. C++利用系统时间产生的随机数

    本文由青松原创并依GPL-V2及其后续版本发放,转载请注明出处且应包含本行声明. C++中常用rand()函数生成随机数,但严格意义上来讲生成的只是伪随机数(pseudo-random integra ...

  6. mybatis关联配置(一对多配置)

    敲代码也有不少日子了,今天碰到个需求,就是定时器生成一张表,但是这个表的某些数据是从另外两张表中拿到的,定外两张表又是一对多的关系,想着咋在一个接口就能敲出来,大概结构如下 然后需要a表的数据(比如张 ...

  7. js中比较实用的函数用法

    <table id="table"> <tr> <th>用户ID</th> <th>用户名</th> < ...

  8. Swift学习笔记 - URL编码encode与解码decode

    使用swift有一段时间了,api的变换造成了很多困扰,下面是关于url编码和解码问题的解决方案 在Swift中URL编码 在Swift中URL编码用到的是String的方法 func addingP ...

  9. [转]常见HTTP状态(如200,304,404,503)

    在网站建设的实际应用中,容易出现很多小小的失误,就像mysql当初优化不到位,影响整体网站的浏览效果一样,其实,网站的常规http状态码的表现也是一样,Google无法验证网站几种解决办法,提及到由于 ...

  10. C#:手把手教你用C#打包应用程序(安装程序卸载程序)

    摘要:本文介绍在C#中手把手教你用C#打包应用程序(安装程序卸载程序) 1:新建安装部署项目 打开VS,点击新建项目,选择:其他项目类型->安装与部署->安装向导(安装项目也一样),然后点 ...