zoukankan      html  css  js  c++  java
  • Hastiness

    Problem Description
    How many problems did you AC?
    When you read this problem, don’t hasty and careless, this is also simple, haha, I didn’t cheat you.
    The game over soon, WisKey starts using English begin countdown. He not only have no gene in math, but also bad in English. Fortunately, He met you who have gift in programming. So please help him to translate. 
     
    Input
    Give you an integer T, output T in English, and note that all of words are lower case. (0<=T<=9999)
     
    Output
    One answer One line.
    Details see sample.
     
    Sample Input
    2034
    1234
    123
    24
    0
     
    Sample Output
    two thousand and thirty-four
    one thousand and two hundred and thirty-four
    one hundred and twenty-three
    twenty-four
    zero
     
     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 int main(){
     5     int number;
     6     int a;
     7     int b;
     8     int c;
     9     char digit[22][20];
    10     char ten[11][20];
    11     int flag=0;
    12 
    13     strcpy(digit[0],"zero");
    14     strcpy(digit[1],"one");
    15     strcpy(digit[2],"two");
    16     strcpy(digit[3],"three");
    17     strcpy(digit[4],"four");
    18     strcpy(digit[5],"five");
    19     strcpy(digit[6],"six");
    20     strcpy(digit[7],"seven");
    21     strcpy(digit[8],"eight");
    22     strcpy(digit[9],"nine");
    23     strcpy(digit[10],"ten");
    24     strcpy(digit[11],"eleven");
    25     strcpy(digit[12],"twelve");
    26     strcpy(digit[13],"thirteen");
    27     strcpy(digit[14],"fourteen");
    28     strcpy(digit[15],"fifteen");
    29     strcpy(digit[16],"sixteen");
    30     strcpy(digit[17],"seventeen");
    31     strcpy(digit[18],"eighteen");
    32     strcpy(digit[19],"nineteen");
    33     strcpy(digit[20],"twenty");
    34 
    35     strcpy(ten[2],"twenty");
    36     strcpy(ten[3],"thirty");
    37     strcpy(ten[4],"forty");
    38     strcpy(ten[5],"fifty");
    39     strcpy(ten[6],"sixty");
    40     strcpy(ten[7],"seventy");
    41     strcpy(ten[8],"eighty");
    42     strcpy(ten[9],"ninety");
    43 
    44     while(scanf("%d",&number)!=EOF){
    45         a=number/1000;
    46         b=number/100%10;
    47         c=number%100;
    48 
    49         if(a!=0){    //当千位不为0时才打印
    50             flag=1;
    51             printf("%s thousand",digit[a]);
    52 
    53             if(b!=0 || c!=0)   //后面不为0才打印"and"
    54                 printf(" and ");
    55         }
    56 
    57         if(b!=0){
    58             flag=1;
    59             printf("%s hundred",digit[b]);
    60 
    61             if(c!=0)
    62                 printf(" and ");
    63         }
    64 
    65         if(c<=20){
    66             if(flag==1 && c==0)  //前面已经打印,此时的0不打印
    67                 ;
    68 
    69             else if(flag==0 && c==0)  //前面没有打印,此时的0打印
    70                 printf("zero");
    71 
    72             else
    73                 printf("%s",digit[c]);   //不为0直接打印
    74         }
    75 
    76         else{
    77             printf("%s",ten[c/10]);  //打印十位数
    78 
    79             if(c%10!=0)   //如果还有个位数,打印"-"和个位数
    80                 printf("-%s",digit[c%10]);
    81         }
    82 
    83         printf("
    ");
    84 
    85     }
    86     
    87     return 0;
    88 }
  • 相关阅读:
    css相关
    文章管理列表
    高性能MySQL基础篇
    mysql
    node.js开发实战
    React Hooks
    client-*,scroll-*,offset-*的区别
    将create-react-app从javascript迁移到typescript
    为Github项目添加Travis持续集成服务
    cookie储存
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/4088022.html
Copyright © 2011-2022 走看看