#3847: WC問題


pellok (哈比熊)


#include<iostream>
#include<cmath>
#include<string>
using namespace std;
string str="零壹貳參肆伍陸柒捌玖拾佰仟萬億";
string menber_change_word(int);
int main(){
    long a;
    while(cin>>a && a>=0 && a<=2147483647){
        if(a<10000){
            cout<<menber_change_word(a%10000)<<endl;
        }else if(a<100000000){
            cout<<menber_change_word(a/10000)<<"萬";
            if(a%10000 <1000 && a%10000 !=0) cout<<"零";
            cout<<menber_change_word(a%10000)<<endl;
        }else{
            cout<<menber_change_word(a/100000000)<<"億";
            if(a%100000000 <100000000 && a%100000000 !=0) cout<<"零";
            a%=100000000;
            if(a!=0) cout<<menber_change_word(a/10000)<<"萬";
            if(a%10000 <1000 && a%10000 !=0) cout<<"零";
            cout<<menber_change_word(a%10000)<<endl;
        }
    }
return 0;
}
string menber_change_word(int x){
    string word="";
    if(x<=9){
        if(x==0) return word;
        word+=str[x%10*2];
        word+=str[x%10*2+1];
    }else if(x<=99 && x>=10){
        word+=str[x/10*2];
        word+=str[x/10*2+1];
        word+=str[20];
        word+=str[21];
        if(x%10==0) return word;
        word+=str[x%10*2];
        word+=str[x%10*2+1];
    }else if(x<=999 && x>=100){
        word+=str[x/100*2];
        word+=str[x/100*2+1];
        x%=100;
        word+=str[22];
        word+=str[23];
        if(x==0) return word;
        if(x<=9){
            word+=str[0];
            word+=str[1];            
        }else{
            word+=str[x/10*2];
            word+=str[x/10*2+1];
            word+=str[20];
            word+=str[21];
        }
        if(x%10==0) return word;
        word+=str[x%10*2];
        word+=str[x%10*2+1];
    }else{
        word+=str[x/1000*2];
        word+=str[x/1000*2+1];
        x%=1000;        
        word+=str[24];
        word+=str[25];
        if(x==0) return word;
        if(x<=99){
            if(x>=10){
                word+=str[0];
                word+=str[1];
            }
        }else{
            word+=str[x/100*2];
            word+=str[x/100*2+1];
            x%=100;
            word+=str[22];
            word+=str[23];
        }
        if(x==0) return word;
        if(x<=9){
            word+=str[0];
            word+=str[1];            
        }else{
            word+=str[x/10*2];
            word+=str[x/10*2+1];
            word+=str[20];
            word+=str[21];
        }
        if(x%10==0) return word;
        word+=str[x%10*2];
        word+=str[x%10*2+1];
    }
    return word;
}
        
與正確輸出不相符(line:1)
您的答案為: ��萬���貟���揃
正確答案為: 壹萬貳仟參佰肆拾伍