当前位置:网站首页>PAT1005

PAT1005

2022-08-09 11:09:00 AlanLiu6

c和c++的函数、语法都忘光了,好惨

https://pintia.cn/problem-sets/994805342720868352/problems/994805519074574336

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char num[1005];

string str[10] = {"zero","one","two","three","four","five","six","seven","eight","nine"};

char s[105];

int main()
{
    //scanf("%s",num);
    int sum = 0;
    while(1)
    {
        char c;
        scanf("%c",&c);
        if(c == '\n' || c == ' ') break;
        sum += c - '0';
    }
    //printf("%d",sum);
    sprintf(s,"%d",sum);
   // printf("%s",s);
   int t = s[0]-'0';
   cout << str[t];
   for(int i = 1;i < strlen(s);i++)
   {
       t = s[i]-'0';
       cout << " " << str[t];
   }
   printf("\n");

    return 0;
}

原网站

版权声明
本文为[AlanLiu6]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Alen666/article/details/97576985