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 ...
随机推荐
- Ubuntu系统下常用的新建、删除、拷贝文件命令
我们在Ubuntu系统中安装程序时,经常要在usr目录下新建.拷贝文件,此文件夹在Linux类系统中需要root权限才能访问,因此用常规的鼠标右键菜单操作是无效的,今天分享一下在终端中使用命令新建.拷 ...
- python学习day3--python基础
1.python不用声明变量的类型,运行时python自己进行判断 2.尽量不要用“+”去拼接字符串,运行时会每遇到一个“+”就开辟一块内存空间,使用如下方式进行字符串的拼接. msg=''' inf ...
- Android简单拨号
package com.example.phonecall; import android.net.Uri; import android.os.Bundle; import android.app. ...
- SQLSERVER2012数据库还原
(1)还原已存在数据库 还原时提示失败,因为数据库正在使用,无法获得独占访问权.解决办法,先分离已存在的数据库,再执行还原操作. 确定后居然成功了,因为我是先使用(2)还原数据库后直接尝试(1)方法还 ...
- 解决TextView在显示文字的时候,一行还没显示满就跳到下一行
转载请注明:转自 http://blog.csdn.NET/u011176685/article/details/48295185 一.问题描述: Android的TextView在显示文字的时候,如 ...
- margin的重叠现象
当两个相邻的普通元素设置margin时,则它们的间距并不是简单的外边距相加. <!DOCTYPE html> <html lang="en"> <he ...
- 终于解决了我的DISCUZ 无法连接到您的服务器,可能您的服务器处于防火墙后端 论坛云平台的问题~
事由:由于前几天折腾备份,将论坛源文件误删了大部分,于是我重新下载了源码,传到了空间. 然后问题来了,我关闭纵横搜索提示“无法连接到您的服务器,可能您的服务器处于防火墙后端”,设置纵横搜索页一直显示“ ...
- 隐藏win7盘符
1.隐藏盘符: //新建注册表,隐藏X盘符 int regeditme() { HKEY hkey; DWORD dwLastError= ;//隐藏X盘2^25 J:2^9=512 X:盘符与挂载的 ...
- L001-oldboy-mysql-dba-lesson01
L001-oldboy-mysql-dba-lesson01 <sql应用重构>经典的书 ,思想,封顶境界! mysql下载页面: http://www.filewatcher ...
- fedora下python3 安装tkinter和pygame
root 下用 “yum search tkinter”,如下图所示: 然后再根据系统选择安装就好了. tkinter安装完毕. 接下来是安装pygame在fedora的python3上,我的是pyt ...