The 5th Zhejiang Provincial Collegiate Programming Contest---ProblemG:Give Me the Number
来源:互联网 发布:centos 7开机密码忘记 编辑:程序博客网 时间:2024/06/05 19:23
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2971
题意:将输入的英文数字表达转化为阿拉伯数字。
#include<bits/stdc++.h>using namespace std;char aa[30][10]= {"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[28]= {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,30,40,50,60,70,80,90};char cc[300][20];int main() { int t; char s[250]; scanf("%d",&t); getchar();//先吃掉t后面的回车 while(t--) { memset(s,0,sizeof(s)); memset(cc,0,sizeof(cc)); gets(s); int num=0,k=0; int len=strlen(s); for(int i=0; i<len; i++) { if(i>=1&&s[i]==' '&&s[i-1]!=' ') { num++;//在’ ‘前算上一个字符串 k=0; continue; } if(s[i]!=' ') cc[num][k++]=s[i];//装入一个字符串 } int sum1=0,sum2=0; int j; //有前至后读入字符串 for(int i=0; i<=num; i++) { for(j=0; j<28; j++) { if(strcmp(cc[i],aa[j])==0) { sum1+=bb[j]; break; } } if(j=28) { if(strcmp(cc[i],"and")==0) continue; if(strcmp(cc[i],"thousand")==0) { sum1*=1000; sum2+=sum1; sum1=0; } else if(strcmp(cc[i],"hundred")==0) sum1*=100; else if(strcmp(cc[i],"million")==0) { sum1*=1000000; sum2+=sum1; sum1=0; } } } printf("%d\n",sum2+sum1); } return 0;}//善于使用strcmp函数,其实想到就很简单了
0 0
- The 5th Zhejiang Provincial Collegiate Programming Contest---ProblemG:Give Me the Number
- The 5th Zhejiang Provincial Collegiate Programming Contest 部分题解
- The 5th Zhejiang Provincial Collegiate Programming Contest
- The 7th Zhejiang Provincial Collegiate Programming Contest
- The 6th Zhejiang Provincial Collegiate Programming Contest
- The 8th Zhejiang Provincial Collegiate Programming Contest / L - Javabeans
- The 8th Zhejiang Provincial Collegiate Programming Contest / M - Median
- The 8th Zhejiang Provincial Collegiate Programming Contest
- The 9th Zhejiang Provincial Collegiate Programming Contest
- The 10th Zhejiang Provincial Collegiate Programming Contest Solution
- The 11th Zhejiang Provincial Collegiate Programming Contest---Talented Chef
- The 11th Zhejiang Provincial Collegiate Programming Contest
- The 11th Zhejiang Provincial Collegiate Programming Contest
- The 11th Zhejiang Provincial Collegiate Programming Contest
- The 11th Zhejiang Provincial Collegiate Programming Contest
- The 12th Zhejiang Provincial Collegiate Programming Contest
- The 12th Zhejiang Provincial Collegiate Programming Contest - A
- The 12th Zhejiang Provincial Collegiate Programming Contest - G
- leetcode练习
- 安装oralce过程中用户、群组及相关oracle inventory的详解
- uva 10169 Urn-ball Probabilities!
- Relay: 全新的React数据获取框架
- java如何进行异常处理
- The 5th Zhejiang Provincial Collegiate Programming Contest---ProblemG:Give Me the Number
- 【千里之行,始于足下】游戏服务端开发--开发语言篇
- Shader 学习一:Shader和渲染管线
- 基于ffmpeg的HLS开源服务器搭建配置及开发详解
- 学C++第一天 面向对象写2杈
- iOS开发之block详解
- The 5th Zhejiang Provincial Collegiate Programming Contest------ProblemK:Kinds of Fuwas
- Shader 学习二:Unity shader 的组织形式
- Basic C++ Container classes summary(Array, Vector, List)