PAT:1002. 写出这个数 (20) AC

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
  char str[111];
  scanf("%s",str);
  int len=strlen(str);
  int sum=0;
  for(int i=0 ; i<len ; ++i)
    sum+=str[i]-'0';
  char A[10][5]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
  int out[50],index=0;
  while(sum!=0)          //将结果下标倒序存入out
  {
    out[index++]=sum%10;
    sum/=10;
  }
  for(int i=index-1 ; i>=0 ; --i)  //再讲结果逆序输出,就是正常的顺序了
  {
    printf("%s",A[out[i]]);
    if(i!=0)
      printf(" ");
  }
  //system("pause");
  return 0;
}
posted on 2015-02-19 23:32  Evence  阅读(517)  评论(0编辑  收藏  举报