PAT甲1005 Spell it right【字符串】

1005 Spell It Right (20 分)

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(≤10​100​​).

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

题意:

给一个最多100位的数字,把各位上的数求和,把结果各位上的数字翻译成英文输出。

思路:

暴力。

 #include <iostream>
#include <set>
#include <cmath>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long LL;
#define inf 0x7f7f7f7f char s[];
string spell[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
int str[]; int main()
{
scanf("%s", s);
int n = strlen(s);
int ans = ;
for(int i = ; i < n; i++){
ans += s[i] - '';
}
int l = ;
if(ans == ){
str[l++] = ;
}
while(ans){
str[l++] = ans % ;
ans /= ;
} cout<<spell[str[l - ]];
for(int i = l - ; i >= ; i--){
cout<<" "<<spell[str[i]];
}
cout<<endl; return ;
}
上一篇:PAT甲题题解-1073. Scientific Notation (20)-字符串处理


下一篇:PAT甲1077 Kuchiguse【字符串】【暴力】【Hash】【二分】