您好,登錄后才能下訂單哦!
#include<iostream> #include<stack> using namespace std; string zhCN[] = {"零","壹","貳","叁","肆","伍","陸","柒","捌","玖"}; //正常記賬范圍內數值 string zhUNIT[] = { "拾","佰","仟","萬","拾","佰","仟","億" ,"拾","佰","仟","萬", "拾","佰","仟"}; int main() { //12,345 ,678, 902 while (1) { char cc[32]; scanf("%s", cc); string str_value(cc); cout << "input value is " << str_value.c_str() << endl; stack<int>nValue; for (int i = 0; i < str_value.length(); i++) { const char cc = str_value.at(i); nValue.push((cc - '0')); } stack<string>cn; int ii = 0; int zcount = 0; while (!nValue.empty()) { int value = nValue.top(); cn.push(zhCN[value]); cn.push(zhUNIT[ii]); nValue.pop(); ii++; } if (!cn.empty()) { cn.pop(); } //刪除零 stack<string>cn2; while (!cn.empty()) { while (cn.top() != zhCN[0]) { cn2.push(cn.top()); cn.pop(); if (cn.empty()) { break; } } if (cn.empty()) { break; } //找到零結束 while (cn.top() == zhCN[0]) { cn.pop(); if (cn.empty()) { break; } if (cn.top() == zhUNIT[3])//保留萬 { cn2.push(zhUNIT[3]); } if (cn.top() == zhUNIT[7])//保留億 { cn2.push(zhUNIT[7]); } cn.pop(); }//找到零結束 if (!cn.empty()) { cn2.push(zhCN[0]); } } stack<string>cn3; string newstr = ""; while (!cn2.empty()) { cn3.push(cn2.top()); cn2.pop(); } while (!cn3.empty()) { newstr += cn3.top(); cn3.pop(); } cout << "newstr is " << newstr.c_str() << endl; } return 0; }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。