zoukankan      html  css  js  c++  java
  • The 5th Zhejiang Provincial Collegiate Programming Contest---ProblemG:Give Me the Number

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2971

    题意:将输入的英文数字表达转化为阿拉伯数字。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 char aa[30][10]= {"zero", "one","two", "three", "four", "five", "six",  "seven", "eight", "nine",
     5                   "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen","nineteen",
     6                   "twenty","thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"
     7                  };
     8 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};
     9 char cc[300][20];
    10 int main() {
    11     int t;
    12     char s[250];
    13     scanf("%d",&t);
    14     getchar();//先吃掉t后面的回车
    15     while(t--) {
    16         memset(s,0,sizeof(s));
    17         memset(cc,0,sizeof(cc));
    18         gets(s);
    19         int num=0,k=0;
    20         int len=strlen(s);
    21         for(int i=0; i<len; i++) {
    22             if(i>=1&&s[i]==' '&&s[i-1]!=' ') {
    23                 num++;//在’ ‘前算上一个字符串
    24                 k=0;
    25                 continue;
    26             }
    27             if(s[i]!=' ')
    28                 cc[num][k++]=s[i];//装入一个字符串
    29         }
    30         int sum1=0,sum2=0;
    31         int j;
            //有前至后读入字符串
    32 for(int i=0; i<=num; i++) { 33 for(j=0; j<28; j++) { 34 if(strcmp(cc[i],aa[j])==0) { 35 sum1+=bb[j]; 36 break; 37 } 38 } 39 if(j=28) { 40 if(strcmp(cc[i],"and")==0) 41 continue; 42 if(strcmp(cc[i],"thousand")==0) { 43 sum1*=1000; 44 sum2+=sum1; 45 sum1=0; 46 } else if(strcmp(cc[i],"hundred")==0) 47 sum1*=100; 48 else if(strcmp(cc[i],"million")==0) { 49 sum1*=1000000; 50 sum2+=sum1; 51 sum1=0; 52 } 53 } 54 } 55 printf("%d ",sum2+sum1); 56 } 57 return 0; 58 }//善于使用strcmp函数,其实想到就很简单了
    我会一直在
  • 相关阅读:
    经方膏方
    荆防柴朴汤
    温经汤治痤疮
    经方治疗带状疱疹
    用排除法诊断半表半里证
    leaflet 学习备忘
    在线数据库设计 初稿 想法简单验证
    SVG PATH 生成器
    模仿bootstrap做的 js tooltip (添加鼠标跟随功能)
    js 生成随机炫彩背景
  • 原文地址:https://www.cnblogs.com/zhien-aa/p/5203081.html
Copyright © 2011-2022 走看看