将一个四位数的整数,输出它的拼音形式。如1001,输出“yiqianlingyi”,10,输出“10”
// wamie2.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include<map> #include<string> #include<iostream> using namespace std; int main() { int number = 0; map<int, string> ismap1; ismap1[0] = "ling"; ismap1[1] = "yi"; ismap1[2] = "er"; ismap1[3] = "san"; ismap1[4] = "si"; ismap1[5] = "wu"; ismap1[6] = "liu"; ismap1[7] = "qi"; ismap1[8] = "ba"; ismap1[9] = "jiu"; ismap1[10] = "shi"; map<int, string> ismap2; ismap2[0] = ""; ismap2[1] = "shi"; ismap2[2] = "bai"; ismap2[3] = "qian"; string temp, ret; while (cin >> number) { int cnt = -1; ret = ""; bool tag = true; if (number < 20) { if (0 == number) cout << "ling" << endl; else { while (0 != number) { ++cnt; temp = ""; int i = number % 10; if (1 == i && 1 == cnt) temp = ismap1[10]; else temp = ismap1[i] + ismap2[cnt]; ret = temp.append(ret); number /= 10; } if (ret.size() >= 5 && "ling" == ret.substr(ret.size() - 4, 4)) ret = ret.substr(0, ret.size() - 4); cout << ret << endl; } } else { while (0 != number) { ++cnt; temp = ""; int i = number % 10; if (true == tag && 0 == i) { temp = ismap1[i]; tag = false; } else { if (0 != i) { temp = ismap1[i] + ismap2[cnt]; tag = true; } } ret = temp.append(ret); number /= 10; } if (ret.size() >= 5 && "ling" == ret.substr(ret.size() - 4, 4)) ret = ret.substr(0, ret.size() - 4); cout << ret << endl; } } return 0; }