PAT A1005 Spell It Right

水题,取到每位操作然后按索引输出就行;

唯一需要注意的就是输入十进制的100次方,超出了整型范围,所以要用字符串来存储;

#include<stdio.h>
#include<stdlib.h>
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
using std::vector;
int main(){
    char number[10][8]={"zero","one","two","three","four","five","six","seven","eight","nine"};
    string s;
    cin>>s;
    int index=0;
    for(int i=0;i<s.size();i++){
        index+=s[i]-'0';
    }
    if(index==0){
        printf("zero");
        system("pause");
        return 0;
    }
    bool flag=true;
    vector<int>v;
    while(index!=0){
        v.push_back(index%10);
        index=index/10;
    }
    for(int i=v.size()-1;i>=0;i--){
        if(i!=0){
            printf("%s ",number[v[i]]);
        }else{
            printf("%s",number[v[i]]);
        }
    }
    system("pause");
    return 0;
}

 

相关文章:

  • 2021-07-19
  • 2021-08-09
  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-12-05
猜你喜欢
  • 2021-05-15
  • 2021-04-26
  • 2021-08-17
  • 2021-10-31
  • 2021-09-22
  • 2021-11-29
相关资源
相似解决方案