完美世界第二题:模拟读数字

测试用例:

102:yibailinger

11:shiyi

1:yi

111:yibaiyishiyi

 1 #include <iostream>
 2 #include <vector>
 3 using namespace std;
 4 /************************************************************************/
 5 /*                       模拟读数字                                       */
 6 /************************************************************************/
 7 void readNumber(const int &number)
 8 {
 9     string result="";
10     vector<string> match(10);
11     match[0] = "ling";match[1] = "yi";match[2] = "er";match[3] = "san";
12     match[4] = "si";match[5] = "wu";match[6] = "liu";match[7] = "qi";
13     match[8] = "ba";match[9] = "jiu";
14     int baiwei = number/100;
15     int shiwei = number%100/10;
16     int gewei = number%10;
17     if (baiwei != 0)
18     {
19         result = match[baiwei];
20         result+="bai";
21         if (shiwei != 0)
22         {
23             result+=match[shiwei];
24             result+="shi";
25         }
26         else
27             result+=match[shiwei];
28         if (gewei != 0)
29             result+=match[gewei];
30     }
31     else
32     {
33         if (shiwei != 0)
34         {
35             if(shiwei != 1)
36                 result = match[shiwei];
37             result+="shi";
38         }
39         if (gewei != 0)
40             result+=match[gewei];
41     }
42     for (int i=0;i<result.size();i++)
43         cout<<result[i];
44     cout<<endl;
45 }
46 int main()
47 {
48     int number;
49     while(cin>>number)
50         readNumber(number);
51     system("pause");
52     return 0;
53 }

 

posted on 2016-04-25 22:15  可乐少爷  阅读(197)  评论(0)    收藏  举报