将数字转化为拼音(1000内)


完美的一道笔试题目
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
char str[10];
int main()
{
      map<int,string>Q;
      Q[0]="ling";
      Q[1]="yi";
      Q[2]="er";
      Q[3]="san";
      Q[4]="si";
      Q[5]="wu";
      Q[6]="liu";
      Q[7]="qi";
      Q[8]="ba";
      Q[9]="jiu";
      Q[100]="bai";
      Q[10]="shi";

      while(~scanf("%s",str))
      {

            int len=strlen(str);
             int i;
            for( i=0;i<len;i++)
                if(str[i]!='0')
                      break;
            for(int j=0;j<len-i;j++)
                  str[j]=str[j+i];
            len-=i;
            if(len>3)
                continue;
            if(len==3)
            {
                 cout<<Q[str[0]-'0'];
                 cout<<Q[100];
                  if((str[1]=='0' && str[2]=='0') )
                  {
                        cout<<endl;
                  }
                  else if(str[1]=='0' && str[2]!='0')
                  {
                        cout<<Q[str[1]-'0']<<Q[str[2]-'0']<<endl;
                  }
                  else if(str[1]!='0' && str[2]=='0')
                  {
                        cout<<Q[str[1]-'0']<<Q[10]<<endl;
                  }
                  else
                  {
                        cout<<Q[str[1]-'0']<<Q[10]<<Q[str[2]-'0']<<endl;
                  }

            }
            else if(len==2)
            {
               if (str[0]=='1' && str[1]!='0')
                cout<<Q[10]<<Q[str[1]-'0']<<endl;
                else{
                  cout<<Q[str[0]-'0']<<Q[10];
                  if(str[1]!='0')
                        cout<<Q[str[1]-'0'];
                  cout<<endl;
                }
            }
            else
                  cout<<Q[str[0]-'0']<<endl;
      }
      return 0;
}


转载于:https://www.cnblogs.com/zhanpang/p/5682874.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值