zoukankan      html  css  js  c++  java
  • HDU 1727 Hastiness

     1 #include<stdio.h>
     2 #include<math.h>
     3 #include<string.h>
     4 #include<stdlib.h>
     5 #include<ctype.h>
     6 #define max(a, b)(a < b ? a : b)
     7 #define N 10010
     8 
     9 char s[10][10] = {"one", "two", "three", "four", "five", "six", "seven","eight", "nine", "ten"};
    10 char s1[10][10] = {"ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
    11 char s2[10][10] = {"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
    12 
    13 int main()
    14 {
    15     int n;
    16     int a[N], j, i, f, g;
    17     while(scanf("%d", &n) != EOF)
    18     {
    19         j = 0, f = 0, g = 0;
    20         memset(a, 0, sizeof(a));
    21         if(n == 0)
    22             printf("zero");
    23         else
    24         {
    25             while(n)
    26             {
    27                 a[j++] = n % 10;
    28                 n /= 10;
    29             }
    30         }
    31         if(j == 1)
    32             printf("%s", s[a[0] - 1]);
    33         else
    34         {
    35             for(i = j - 1 ; i >= 0 ; i--)
    36             {
    37                 if(i == 3)
    38                     printf("%s thousand", s[a[i] - 1]), f = 1;
    39                 else if(i == 2)
    40                 {
    41                     if(a[i] != 0)
    42                     {
    43                         if(f == 1)
    44                             printf(" and ");
    45                         printf("%s hundred", s[a[i] - 1]);
    46                     }
    47                     if(a[i - 1] != 0 || a[i - 2] != 0)
    48                         g = 1;
    49 
    50                 }
    51                 else if(i == 1)
    52                 {
    53                     if(g == 1)
    54                         printf(" and ");
    55                     if(a[i] == 1 && a[i - 1] != 0)
    56                         printf("%s", s2[a[i - 1] - 1]);
    57                     else
    58                     {
    59                         if(a[i] == 0)
    60                             printf("%s", s[a[i - 1] - 1]);
    61                         else
    62                         {
    63                             if(a[i - 1] == 0)
    64                                 printf("%s", s1[a[i] - 1]);
    65                             else
    66                             {
    67                                 printf("%s-%s", s1[a[i] - 1], s[a[i - 1] - 1]);
    68                             }
    69                         }
    70                     }
    71                 }
    72             }
    73         }
    74         printf("
    ");
    75     }
    76     return 0;
    77 }

    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
    

    Author

    威士忌

    Source

    HZIEE 2007 Programming Contest
     
     
     
     
     
  • 相关阅读:
    【转】Linux逻辑卷管理
    oracle range分区表已经有了MAXVALUE 分区,如何添加分区?要不能删除MAXVALUE分区里的数据,不影响在线应用。
    切换用户后whoami打印用户的问题
    tomcat版本号修改已dwr配置错误安全漏洞整改
    [LeetCode]: 64: Minimum Path Sum
    [LeetCode]: 292: Nim Game
    [LeetCode]: 22 : Generate Parentheses
    [LeetCode]: 121: Best Time to Buy and Sell Stock
    [LeetCode]: 62: Unique Paths
    [LeetCode]: 145: Binary Tree Postorder Traversal
  • 原文地址:https://www.cnblogs.com/yishilin/p/4448331.html
Copyright © 2011-2022 走看看