您好,登錄后才能下訂單哦!
請(qǐng)實(shí)現(xiàn)一個(gè)函數(shù),給定一個(gè)32為有符號(hào)整數(shù)(int 類型),函數(shù)輸出該數(shù)字符合漢語習(xí)慣的讀法。例如:10086 讀作 " 一萬零八十六"。
#include<iostream> #include<list> #include<string> #include<stdlib.h> #include<math.h> using namespace std; void m_itoa(int num,list<char> &vt) { int n=num; if(num<0) n=abs(num); while(n>0) { vt.push_front(n%10+'0'); n/=10; } } int main() { string n1[]={"零","一","二","三","四","五","六","七","八","九"}; string n2[]={"個(gè)","十","百","千","萬","十","百","千","億","十"}; int num; cin>>num; if(num<0) cout<<"負(fù)"; list<char> vt; m_itoa(num,vt); list<char>::iterator str; int i=vt.size(); for(str=vt.begin();str!=vt.end();--i,++str) { if(*str=='0') { if(i>8) cout<<n2[8]; else if(i<8 && i>4) cout<<n2[4]; while(*str=='0') { str++;i--; } if(str==vt.end()) break; else cout<<n1[0]; } cout<<n1[*str-'0']; if(i>1) cout<<n2[i-1]; } cout<<endl; return 0; }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。