PAT1005. Spell It Right

#include<string>
#include<vector>
#include<iostream>
using namespace std;
char *p[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int main(){
  int total(0);
  for(char c;cin>>c;)total+=c-'0';

  if(total){
    vector<int>ret;
    while(total){ret.push_back(total%10);total/=10;}
    for(auto it=ret.rbegin();it!=ret.rend();++it){
      if(it!=ret.rbegin())cout<<' ';
      cout<<p[*it];}
  }//if
  else cout<<"zero";
  return 0;
}

你可能感兴趣的:(PAT1005. Spell It Right)