把每个位上的数字求和sum,然后以英文单词的形式输出sum的每个位
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <vector> using namespace std; /* 把每个位上的数字求和sum,然后以英文单词的形式输出sum的每个位 水 */ char word[10][20]={"zero","one","two","three","four","five","six","seven","eight","nine"}; int main() { char str[105]; scanf("%s",str); int len=strlen(str); int sum=0; for(int i=0;i<len;i++){ sum+=str[i]-‘0‘; } //printf("sum:%d\n",sum); sprintf(str,"%d",sum); len=strlen(str); int idx=str[0]-‘0‘; printf("%s",word[idx]); for(int i=1;i<len;i++){ idx=str[i]-‘0‘; printf(" %s",word[idx]); } return 0; }
时间: 2024-10-14 13:58:08