PAT 甲级 1005. Spell It Right (递归)

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.

Input Specification:

Each input file contains one test case. Each case occupies one line which contains an N (<= 10100).

Output Specification:

For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.

Sample Input:
12345
Sample Output:
one five

此题有个坑,首先题目中输入结果N <=10100, N比较小,一开始就直接用int 存N,但是怎么都不能ac,然后看了一下测试样例,Tony马的,12345>10100了,肯定是int不够大来存N了,改用string,结果就ac

#include <iostream>
#include "cstring"
#include <stdio.h>
#include "iomanip"
#include "vector"
#include "cmath"
#include "stack"
#include "algorithm"
#include <math.h>
#include "map"
#include "queue"
using namespace std;
string a;
int qqqqqqq;
string num[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int abc(int sizee)
{
    int ss=--sizee;
    if(!sizee)
        return (int)a[sizee]-48;

    return (int)a[sizee]-48+abc(sizee);

}
void out (int qq)
{
    if(!qq)
    {
        return;
    }

     out(qq/10);
     cout<<num[qq%10];
     if(qq!=qqqqqqq)

     cout<<" ";
 }
int main()
{

 
    cin>>a;
    int qq=
    abc(a.length() );qqqqqqq=qq;
 
    out(qq  );
    if(!qq)
        cout<<"zero";

 return  0;


}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章