首页 > 代码库 > 1005 Spell It Right (20)

1005 Spell It Right (20)

 1 #include <string> 2 #include <sstream> 3 #include <iostream> 4 using namespace std; 5  6 int main() 7 { 8     string str; 9     char num[10][6]={"zero","one","two","three","four","five","six","seven","eight","nine"};10     while(getline(cin,str))11     {12         int sum=0;13         for(int i=0;i<str.length();i++)14             sum+=str[i]-0;15         string result;16         stringstream ss;17         ss<<sum;18         ss>>result;19 20         for(int i=0;i<result.length();i++)21         {22             if(i==0) printf("%s",num[ result[i]-0 ]);23             else  printf(" %s",num[ result[i]-0 ]);24             //printf("%c",result[i]);25         }26         printf("\n");27     }28     return 0;29 }

 

1005 Spell It Right (20)