The 5th Zhejiang Provincial Collegiate Programming Contest---ProblemG:Give Me the Number
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2971
题意:将输入的英文数字表达转化为阿拉伯数字。
#include<bits/stdc++.h>
using namespace std; char aa[][]= {"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"
};
int bb[]= {,,,,,,,,,,,,,,,,,,,,,,,,,,,};
char cc[][];
int main() {
int t;
char s[];
scanf("%d",&t);
getchar();//先吃掉t后面的回车
while(t--) {
memset(s,,sizeof(s));
memset(cc,,sizeof(cc));
gets(s);
int num=,k=;
int len=strlen(s);
for(int i=; i<len; i++) {
if(i>=&&s[i]==' '&&s[i-]!=' ') {
num++;//在’ ‘前算上一个字符串
k=;
continue;
}
if(s[i]!=' ')
cc[num][k++]=s[i];//装入一个字符串
}
int sum1=,sum2=;
int j;
//有前至后读入字符串
for(int i=; i<=num; i++) {
for(j=; j<; j++) {
if(strcmp(cc[i],aa[j])==) {
sum1+=bb[j];
break;
}
}
if(j=) {
if(strcmp(cc[i],"and")==)
continue;
if(strcmp(cc[i],"thousand")==) {
sum1*=;
sum2+=sum1;
sum1=;
} else if(strcmp(cc[i],"hundred")==)
sum1*=;
else if(strcmp(cc[i],"million")==) {
sum1*=;
sum2+=sum1;
sum1=;
}
}
}
printf("%d\n",sum2+sum1);
}
return ;
}//善于使用strcmp函数,其实想到就很简单了
The 5th Zhejiang Provincial Collegiate Programming Contest---ProblemG:Give Me the Number的更多相关文章
- nenu contest3 The 5th Zhejiang Provincial Collegiate Programming Contest
ZOJ Problem Set - 2965 Accurately Say "CocaCola"! http://acm.zju.edu.cn/onlinejudge/showP ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest May Day Holiday
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5500 The 12th Zhejiang Provincial ...
- 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(第二部分)
Floor Function Time Limit: 10 Seconds Memory Limit: 65536 KB a, b, c and d are all positive int ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Beauty of Array
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Convert QWERTY to Dvorak
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5502 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Demacia of the Ancients
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5504 The 12th Zhejiang Provincial ...
- zjuoj The 12th Zhejiang Provincial Collegiate Programming Contest Ace of Aces
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5493 The 12th Zhejiang Provincial ...
随机推荐
- 每天一道LeetCode--118. Pascal's Triangle(杨辉三角)
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- Agile.Net 组件式开发平台 - 脚本管理组件
脚本管理组件用于管理系统查询脚本,由于数据查询的复杂性和可变性,平台规范要求使用查询使用建立在脚本管理器中的SQL语句.新增.更新.删除数据采用数据访问支持库API. 示例如下: 首先在脚本管理器中定 ...
- 接口(interface)
接口(interface) 接口(interface)定义了一个可由类和结构实现的协定.接口可以包含方法.属性.事件和索引器.接口不提供它所定义的成员的实现-它仅指定实现该接口的类或结构必须提供的成员 ...
- PHP基础在线视频教程高清版
这个是我给大家介绍的PHP基础在线视频教程高清版,目前PHP慢慢垄断WEB的语言编写市场了,PHP 是一种服务器内置式的script 语言,它的出现使得在unix上快速地开发动态web成为现实.PHP ...
- xamarin.ios 豆瓣电台视频教程
视频中提到的网址: http://www.sufeinet.com/thread-655-1-1.html https://github.com/akfish/fm-terminal/blob/dev ...
- L006-oldboy-mysql-dba-lesson06
L006-oldboy-mysql-dba-lesson06 数据清理状态,先标记update table state=1,再删除. myisam没外键,硬件,并发,锁表力度,不支持事务,OLAP. ...
- 表格细边框 并且CSS3加圆角
.YJ table{width:625px;height:860px;text-align:center;overflow:hidden; background:#fff;border-radius: ...
- [转]Linux/Unix系统镜像/备份/恢复 (dd 命令使用)
ref: http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=22561912&id=156879 开源系统默认安装了一个d ...
- discuz管理中心无法登陆
检查下配置文件,当前管理是不是创始人. 如是,那试下修改数据库,在数据表出错时也会这样,还有一个也同时试下 \config\config_global.php 文件 $_config['admincp ...
- php版获取重定向后地址的代码分享
如何获取重定向的地址呢?我们用php实现这样的功能,分享下我的代码,有需要的朋友参考下. 代码如下: <?php //取重定向的地址 class RedirectUrl{ //地址 var $u ...