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的更多相关文章

  1. nenu contest3 The 5th Zhejiang Provincial Collegiate Programming Contest

    ZOJ Problem Set - 2965 Accurately Say "CocaCola"!  http://acm.zju.edu.cn/onlinejudge/showP ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...

  6. 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 ...

  7. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...

  8. 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 ...

  9. 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 ...

  10. 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 ...

随机推荐

  1. ASP判断当前页面上是否有参数ID传递过来

    遇到了一个这样的ASP问题: 在当前页面上判断,是否有参数ID传递过来? 如果没有,显示“没有参数传递过来”. 如果有传递,但值为空,显示“存在参数,但参数为空” <% if (request( ...

  2. 初学Android: 四大组件之Activity

    1.activity (1)一个Activity通常就是一个单独的屏幕(窗口),简单来说activity就是一个交互界面,一般应用程序都要由一个或者多个activity组成. (2)Activity之 ...

  3. 解释清楚c++的重载操作符【用自己的话,解释清楚】

    C++中对于内置的变量及标准库中常见的类定义类常见的操作符含义,对于自定义的类也可以通过关键字operate 重载操作符的含义. C++中支持重载的目的 诚然操作符的重载可以通过使用函数实现同样的功能 ...

  4. datatable dateset 载体传递数据、存储过程

    第一部分:数据库通过存储过程读取数据,通过datatable接受,前台通过asp:repeater.DataSource()和binding()绑定数据 /// <summary> /// ...

  5. 从客户端中检测到有潜在危险的 request

    如题,当遇到这种情况该怎么办呢? 通常情况下一下2种解决方案就可以解决问题了:    解决方案一:     在.aspx文件头中加入这句:     <%@ Page validateReques ...

  6. UEditor上传图片等附件都出现红叉

    我的环境: vs2010+netframework3.5+ueditor1_3_5-utf8-net 问题:UEditor上传图片等附件都出现红叉 尝试了网络上各种方法都不对, 后来只能自己看下ima ...

  7. Linux小白最佳实践:《超容易的Linux系统管理入门书》(连载五)Linux系统的对话方式

    本篇是Linux小白最佳实践第5篇,目的就是让白菜们了解Linux进程之间是如何对话的.之前连载的几篇,在微信上引起了很多的反响,有人也反映图多文字少,感觉没有干货.本篇选了大部分是实战讲解的&quo ...

  8. uva673 - Parentheses Balance(栈)

    题意:1.空串合法.2.若A和B合法,则AB合法.3.若A合法,则(A)和[A]合法. 思路:遍历串,遇到(或[,则压入队列,若遇到),判断:若栈空,则不合法:若栈顶元素不是(,也不合法.]同理.因为 ...

  9. Java使用泛型类来提高方法的可重用性

    我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3832268.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体验 ...

  10. mysql配置优化测试

    http://bjlfp.blog.163.com/blog/static/77368461201211695924524/ 感觉真不错啊.观察几天看看