A four-digit integer that outputs its phonetic form. such as 1001, output "Yiqianlingyi", 10, output "10"
//wamie2.cpp: Defines the entry point of the console application. //#include"stdafx.h"#include<map>#include<string>#include<iostream>using namespacestd;intMain () {intNumber =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[Ten] ="Shi"; Map<int,string>ISMAP2; ismap2[0] =""; ismap2[1] ="Shi"; ismap2[2] ="Bai"; ismap2[3] ="Qian"; stringtemp, ret; while(Cin >>Number ) { intCNT =-1; RET=""; BOOLTag =true; if(Number < -) { if(0==Number ) cout<<"Ling"<<Endl; Else { while(0!=Number ) { ++CNT; Temp=""; inti = number%Ten; if(1= = I &&1==cnt) Temp= ismap1[Ten]; ElseTemp= Ismap1[i] +ismap2[cnt]; RET=Temp.append (ret); number/=Ten; } 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=""; inti = number%Ten; 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/=Ten; } if(Ret.size () >=5&&"Ling"= = Ret.substr (Ret.size ()-4,4)) RET= Ret.substr (0, Ret.size ()-4); cout<< ret <<Endl; } } return 0;}
Perfect World Online Written test programming question 2