您的位置:首页 > 其它

1005. Spell It Right (20)

2015-06-07 08:23 337 查看
#include<iostream>
#include<map>
#include<string>
#include<stack>
using namespace std;

int main()
{
       map<int, string>M;
       M[1]="one"; M[2]="two"; M[3]="three"; M[4]="four"; M[5]="five";
       M[6]="six"; M[7]="seven"; M[8]="eight"; M[9]="nine"; M[0]="zero";
       string S;
       while( cin>>S )
       {
            int N=0;
            for( int i=0; i<S.size(); i++ )
                N+=S[i]-'0';
            stack<string>Stk;
            if(N==0)
                Stk.push(M[0]);
            while(N)
            {
                  Stk.push(M[N%10]);
                  N/=10;
            }
            cout<<Stk.top();
            Stk.pop();
            while(!Stk.empty())
            {
                cout<<" "<<Stk.top();
                Stk.pop();
            }
            cout<<endl;
       }
       return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: