zoukankan      html  css  js  c++  java
  • 数学趣题——数字翻译器

    问题:输入一个正整数N,输出英文表达。例如:1对应one

    源码:

       1: #include <stdio.h>
       2:  
       3: char data_1[19][11] = {"one", "two", "three", "four",
       4:                        "five", "six", "seven", "eight",
       5:                        "nine", "ten", "eleven", "twelve",
       6:                        "thirteen", "forteen", "fifteen", "sixteen",
       7:                        "seventeen", "eighteen", "ninteen"
       8:                       };
       9:  
      10: char data_2[8][8] = {"twenty", "thirty", "forty", "fifty",
      11:                      "sixty", "seventy", "eighty", "ninty"
      12:                     };
      13:  
      14: void translation_A(long N);
      15: void translation_B(long a);
      16: void translation_C(long b);
      17:  
      18: void translation_A(long N)
      19: {   /*翻译千位数*/
      20:     long a;
      21:  
      22:     if(N == 0) {
      23:         printf("Zero\n");
      24:         return;
      25:     }
      26:  
      27:     a = N / 1000;
      28:  
      29:     if(a != 0) {
      30:         translation_B(a);
      31:         printf("thousand ");
      32:     }
      33:  
      34:     a = N % 1000;
      35:  
      36:     if(a != 0)
      37:         translation_B(a);
      38: }
      39:  
      40: void translation_B(long a)
      41: {   /*翻译百位数*/
      42:     long b;
      43:     b = a / 100;
      44:  
      45:     if(b != 0) {
      46:         translation_C(b);
      47:         printf("hundred ");
      48:     }
      49:  
      50:     b = a % 100;
      51:  
      52:     if(b != 0)
      53:         translation_C(b);
      54: }
      55:  
      56: void translation_C(long b)
      57: {   /*翻译十位数和个位数*/
      58:     long c;
      59:  
      60:     if(b <= 19)
      61:         printf("%s ", data_1[b-1]);
      62:     else
      63:     {
      64:         c = b / 10;
      65:         printf("%s ", data_2[c-2]);
      66:         c = b % 10;
      67:  
      68:         if(c != 0)
      69:             printf("%s ", data_1[c-1]);
      70:     }
      71: }
      72:  
      73: int main()
      74: {
      75:     long N;
      76:     printf("Please input a longeger from 0~999999\n");
      77:     scanf("%ld", &N);
      78:     translation_A(N);
      79:     return 0;
      80: }
  • 相关阅读:
    算法练习题
    牛XX面试题
    web前端面试题
    在js中什么情况下会返回undefined
    yarn
    Web 开发技巧
    dll 文件创建与使用
    【转】 VS2008在64位Windows平台上编译ArcEngine导致HRESULT:0x80040154 (REGDB_E_CLASSNOTREG)错误的解决办法
    Googlemap获取经纬度For APIV3
    javascript局部变量/全局变量
  • 原文地址:https://www.cnblogs.com/steven_oyj/p/1744218.html
Copyright © 2011-2022 走看看