您的位置:首页 > 其它

[PAT] 1005 Spell It Right (20)

2017-10-22 15:50 134 查看
题意是给你几个数,让你输出他们求和后的每个数的英文,如12345输出 one five

//已AC代码
#include<bits/stdc++.h>
using namespace std;
stack<int> s;
int main()
{
string b[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
char a[100860]={'$'};
while(~scanf("%s",&a))
{

int sum=0;
int count=0;
int n=strlen(a);
for(int i=0;i<n;i++)
{
sum+=(a[i]-'0');
}
if(sum==0)
{
cout<<"zero"<<endl;
continue;
}
while(sum)
{
s.push(sum%10);
count++;
sum=sum/10;
}
while(!s.empty())
{
int tmp=s.top();
if(count==1)
cout<<b[tmp]<<endl;
else
cout<<b[tmp]<<" ";
count--;
s.pop();
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: