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;


}


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