完美世界第二题:模拟读数字
生活随笔
收集整理的這篇文章主要介紹了
完美世界第二题:模拟读数字
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
測試用例:
102:yibailinger
11:shiyi
1:yi
111:yibaiyishiyi
1 #include <iostream> 2 #include <vector> 3 using namespace std; 4 /************************************************************************/ 5 /* 模擬讀數(shù)字 */ 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 }?
轉(zhuǎn)載于:https://www.cnblogs.com/keleshaoye/p/5432983.html
總結(jié)
以上是生活随笔為你收集整理的完美世界第二题:模拟读数字的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我的Android进阶之旅------解
- 下一篇: Exchanger的使用