标签:style blog color os io for ar div
1 include<iostream> 2 using namespace std; 3 #include<string> 4 5 typedef int T; 6 7 class List{ 8 struct Node{ 9 T data1; 10 string data2; 11 Node* next; 12 Node(const T& t=T(), string s=string()):data1(t),data2(s){next = NULL;} 13 }; 14 Node* head; 15 public: 16 List():head(NULL){} 17 ~List(){clear();} 18 19 void travel(){ 20 if(head == NULL) 21 return; 22 Node* p = head; 23 while(p != NULL){ 24 cout << p->data1 << p->data2 << ‘ ‘; 25 p = p->next; 26 } 27 } 28 void insert_front(const T& t, string s){ 29 Node* p = new Node(t, s); 30 p->next = head; 31 head = p; 32 } 33 void clear(){ 34 if(head == NULL) 35 return; 36 Node* p = head; 37 while(p != NULL){ 38 p = p->next; 39 delete head; 40 head = p; 41 } 42 } 43 }; 44 45 int size(double n){ 46 int cnt = 1; 47 for(; n >= 10;){ 48 n = n/10; 49 cnt++; 50 } 51 return cnt; 52 } 53 int main() 54 { 55 List l; 56 string arr[9] = {"元", "拾", "佰", "仟", "万", "拾万", "佰万", "仟万", "亿"}; 57 double dRmb; 58 double dTmp; 59 string tail = "整"; 60 string strJiao = "角"; 61 string strFen = "分"; 62 int iJiao; 63 int iFen; 64 int iRmb; 65 bool tag = true; 66 cout << "Please input rmbNum:" << endl; 67 cin >> dRmb; 68 iRmb = (int)dRmb; 69 dTmp = (dRmb - iRmb) * 100; 70 cout << endl; 71 if(size(dRmb) > 9){ 72 cout << "The input number is too long!"; 73 return -1; 74 } 75 if(dRmb != (int)dRmb) 76 tag = false; 77 for(int i = 0; dRmb > 0 && i < 9; ){ 78 l.insert_front((int)dRmb%10, arr[i++]); 79 dRmb = (int)dRmb/10; 80 } 81 if(tag){ 82 l.travel(); 83 cout << tail << endl; 84 } 85 else{ 86 iFen = (int)dTmp%10; 87 dTmp = dTmp/10; 88 iJiao = (int)dTmp%10; 89 l.travel(); 90 if(iFen == 0) 91 cout << iJiao << strJiao << endl; 92 else 93 cout << iJiao << strJiao << ‘ ‘ << iFen << strFen << endl; 94 } 95 }
用链表实现表单金额的大写格式输出,布布扣,bubuko.com
标签:style blog color os io for ar div
原文地址:http://www.cnblogs.com/JingyiLu/p/3916195.html