当前位置: 代码迷 >> 综合 >> PAT1005 Spell It Right(水)
  详细解决方案

PAT1005 Spell It Right(水)

热度:15   发布时间:2023-11-08 14:50:31.0

分析:水题,数位求和,特判断0即可

#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
ll ans=0,res=0;
int a[1100000];
string ss;
string s[11]={
    "zero","one","two","three","four","five","six","seven","eight","nine"};
int main(){
    std::ios::sync_with_stdio(false);cin>>ss;int len=ss.length();for(int i=0;i<len;i++){
    ans+=ss[i]-'0';}if(ans==0) {
    cout<<"zero"<<endl; return 0;}ll pos=0;while(ans>0){
    a[pos++]=ans%10;ans=ans/10;}for(int i=pos-1;i>=0;i--){
    cout<<s[a[i]];if(i!=0) cout<<" ";else cout<<endl;}return 0;
}