G - Give Me the Number --- (first qualifying)
2015-07-27 18:02
134 查看
G - Give Me the Number
时限:2000MS 内存:65536KB 64位IO格式:%lld
& %llu
问题描述
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.
输入
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.
输出
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.
样例输入
样例输出
分析:我本来打算第二题就是这道的,然而嫌麻烦,写到一半就放弃了,去AC其他题了。后来挺后悔的,我的first blood啊,呜呜············这道题也没什么好说的,其实是蛮简单的。遇到一百,乘以一百,遇到一千,乘以一千,把每位加起来就行了。
CODE:
时限:2000MS 内存:65536KB 64位IO格式:%lld
& %llu
问题描述
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.
输入
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.
输出
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.
样例输入
3 one eleven one hundred and two
样例输出
1 11 102
分析:我本来打算第二题就是这道的,然而嫌麻烦,写到一半就放弃了,去AC其他题了。后来挺后悔的,我的first blood啊,呜呜············这道题也没什么好说的,其实是蛮简单的。遇到一百,乘以一百,遇到一千,乘以一千,把每位加起来就行了。
CODE:
<span style="font-size:24px;">#include <iostream> #include <string.h> #include <cstdio> using namespace std; struct node{ string str; int num; }n[1005]; int main() { string tmp1[20]={"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen","fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"}; for(int i=0;i<20;i++){ n[i].str=tmp1[i]; n[i].num=i; } string tmp2[10]={ "","","twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty","ninety"}; for(int i=2;i<10;i++){ n[i*10].str=tmp2[i]; n[i*10].num=i*10; } int t; cin>>t; char ch; ch=getchar(); while(t--){ int res=0,tmp=0; char c[10005]; string s; gets(c); int len=strlen(c); for(int i=0;i<=len;i++){ if(c[i]==' '||i==len){ bool flag=false; for(int i=0;i<100;i++){ if(n[i].str==s){ tmp+=n[i].num; flag=true; break; } } if(!flag){ if(s=="hundred") tmp*=100; else if(s=="million"){ tmp*=1000000; res+=tmp; tmp=0; } else if(s=="thousand"){ tmp*=1000; res+=tmp; tmp=0; } } // cout<<res<<endl; s.erase(); } else s+=c[i]; } cout<<res+tmp<<endl; } return 0; }</span>
相关文章推荐
- 心中的激动与兴奋交加,阿里内推面试
- Cocos2d-x事件分发机制学习笔记
- Block的使用--页面传值方法及探究
- Android、iOS大不同——生命周期
- SQL Server 2008 R2 安装出错:Could not open key
- 了解HTML5和“她”的 API (三)
- flash播放mp4插件轻松搞定播放视频问题
- Cocos2d-x事件分发机制学习笔记 分类: cocos2d代码编写 2015-07-27 18:02 6人阅读 评论(0) 收藏
- Cocos2d-x中,onEnter与init的区别
- Java笔记之线程池
- 【转载】初学makefile
- Python去除多余空格
- H3C 链路聚合协议
- cas login-webflow.xml分析。关于TGT何时生成和存储。
- ssh 反向代理
- 网络爬虫heritrix 3.1 在Windows上的搭建与使用方法说明
- 修复Xcode升级错误 — PCH File Error
- httpwebreqeust读取httponly的cookie
- [考试维护]时隔半年的考试系统
- HashMap的实现