1082 Read Number in Chinese (25 分)

1082 Read Number in Chinese (25 分)
Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output Fu first if it is negative. For example, -123456789 is read as Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu. Note: zero (ling) must be handled correctly according to the Chinese tradition. For example, 100800 is yi Shi Wan ling ba Bai.

Input Specification:
Each input file contains one test case, which gives an integer with no more than 9 digits.

Output Specification:
For each test case, print in a line the Chinese way of reading the number. The characters are separated by a space and there must be no extra space at the end of the line.

Sample Input 1:
-123456789
Sample Output 1:
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu
Sample Input 2:
100800
Sample Output 2:
yi Shi Wan ling ba Bai

自己的思路:整体上是一个数字(traverse)后跟着一个位(chinese)但要处理以下特殊情况
1.负数
2.末尾的处理

2.1 普通末尾
2.2 末尾为零

3.零的处理

这样的思路还是枚举法,很容易少考虑到一些情况,如果实战真用这种法方,那心态估计早就崩了吧。。。。。。


#include<stdio.h>
#include<string.h>
int main(){
  char a[11];
  char traverse[10][10] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
  char chinese[10][10] = {"Yi", "Qian", "Bai", "Shi", "Wan", "Qian", "Bai", "Shi"};
  int i,j,k,n;
  int lastone;
  int specialflag = 0;
  scanf("%s",a);

  n  = strlen(a);

  if(a[0] == '-') {  printf("Fu "); i = 1;   }
  else i = 0;
  if(n >= 9 ){
    for(k = i + 1, j = k+4; k < j; k++)
        if(a[k] != '0') break;
        else specialflag ++;
  }
  lastone = n-1;
  while(a[lastone] == '0'){lastone--;}
  while(a[i] == '0') i++;
  for(; i <  n - 1; i++) {
    if(a[i] != '0' || (a[i + 1] != '0' && a[i] == '0' && i < n - 1 && strcmp(chinese[i + 9 - n] , "Wan") != 0))
        printf("%s ", traverse[a[i] - '0']);
   // { printf("ling ");  continue;}
    if(((a[i] != '0')||(a[i] == '0' && strcmp(chinese[i + 9 - n] , "Wan") == 0 && specialflag != 4 ))){
        if(i < lastone )
            printf("%s ", chinese[i + 9 - n]);
        else {
            if(i + 9 - n < 4 && specialflag != 4)  printf("%s ", chinese[i + 9 - n]);
            else printf("%s", chinese[i + 9 - n]);
        }
    }
  }
  if(a[i] != '0')
        printf("%s", traverse[a[i] - '0']);
  //printf("ajdkfl");

}

未完 测试点三一直没过。

感觉就像熟悉的大二freescale式的if else 代码

好吧解决掉了,忘记处理单零的情况,哭晕在厕所。。。。。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值