1. 把输入的double数看成string类型,先读整数部分后读小数部分;
  2. 整数部分的长度j减去当前字符所在位置i即当前数所在的权重位;即每一位可以读作ge[s[i]-'0'] + ot[j-i-1];(遵循从高位往低位读)
  3. 对应位碰上0则不读,但如果该权重位在万,亿,万亿,万万亿上,则无需读零,但需输出权重位的读法(万,亿);这样才能保证100000读成拾万,而不是读成拾。例外:100000000应读成壹亿,而非壹亿万。
  4. 对应位不为0,但前一位为0,则补读零。
  5. 例外:10应读成拾元而非壹拾元。
#include <iostream>
using namespace std;

string ge[10] = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
string ot[17] = { "", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾",
     "佰", "仟", "万", "拾", "佰", "仟","万" };

void readItAfterPlot(string num)
{
    if(num == "00") {
        cout << "整";
        return ;
    }
    if (num[0] > '0') {
        cout << ge[num[0]-'0'] << "角";
    }
    if (num[1] > '0') {
        cout << ge[num[1]-'0'] << "分";
    }
    return ;
}

void readItBeforePlot(string s)
{
    if (s == "0") return;
    int j = s.size()-1;
    if(!(j%4 == 1 && s[0] == '1')) {
        cout << ge[s[0]-'0'];
    }
    cout << ot[j];
    for(int i = 1; i < s.size(); i++)
    {
        if( (j-i)%4 == 0  && s[i] == '0') {
            if (i >= 4 && j-i == 4 && s[i-1] + s[i-2] + s[i-3] == '0'*3) continue; // 100000001.11
            cout << ot[j-i];
            continue;
        }
        if(s[i] != '0') {
            if(s[i-1] == '0') cout << "零";
            //if(!((j-i)%4 == 1 && s[i] == '1')) {
                // 513.00 是伍佰壹拾叁元还是伍佰拾叁元的区别。
                cout << ge[s[i]-'0'];
            //}
            cout << ot[j-i];
        }
    }
    cout << "元";
    return ;
}

int main()
{
    string s;
    while(getline(cin, s))
    {
        int idx = s.find('.');
        string t1 = s.substr(0, idx);
        string t2 = s.substr(idx+1);
        cout << "人民币";
        readItBeforePlot(t1);
        readItAfterPlot(t2);
        cout << endl;
    }
    return 0;
}

https://github.com/ultraji/nowcoder