1005 Spell It Right

开个string数组存数字英文。

因为数为10100,所以和最多为900,int求和就够了。水题~

#include<iostream>
#include<algorithm>
#include<string.h>
#define maxn 25
using namespace std;
typedef long long ll;
char s[maxn];
string num[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int a[10];
int main()
{
    int ans=0;
    cin>>s;
    int len=strlen(s);
    for(int i=0;i<len;i++)
    {
        ans+=s[i]-'0';
    }
    int p=0;
    while(ans)
    {
        a[p++]=ans%10;
        ans=ans/10;
    }
    cout<<num[a[p-1]];
    for(int i=p-2;i>=0;i--)
        cout<<" "<<num[a[i]];
}
View Code

 

posted on 2018-11-27 20:58  FTA_Macro  阅读(94)  评论(0编辑  收藏  举报

导航