首页 > 学院 > 开发设计 > 正文

PAT (Advanced Level) Practise 1005. Spell It Right (20)

2019-11-06 09:15:57
字体:
来源:转载
供稿:网友

1005. Spell It Right (20) 时间限制: 400 ms内存限制: 65536 kB代码长度限制: 16000 B判题程序:Standard
  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   Each input file contains one test case. Each case occupies one line which contains an N (<= 10100). Output   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. Examples

Input
12345
Output
one five

  Notes    作者   CHEN, Yue

  注意N最大可达100位。

#include <iostream>#include <algorithm>#include <map>#include <vector>#include <functional>#include <string>#include <cstring>#include <queue>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <sstream>#include <iomanip>using namespace std;#define IOS ios_base::sync_with_stdio(false)#define TIE std::cin.tie(0)#define MIN2(a,b) (a<b?a:b)#define MIN3(a,b) (a<b?(a<c?a:c):(b<c?b:c))#define MAX2(a,b) (a>b?a:b)#define MAX3(a,b,c) (a>b?(a>c?a:c):(b>c?b:c))typedef long long LL;typedef unsigned long long ULL;const int INF = 0x3f3f3f3f;const double PI = 4.0*atan(1.0);const double eps = 1e-6;//system("pause");const int maxn = 105;string a;string str[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};stack<string> st;int n, sum;int main(){ cin >> a; sum = 0; for (int i = 0; i < a.size(); i++) sum += a[i] - '0'; do{ st.push(str[sum % 10]); sum /= 10; } while (sum); bool first = true; while (st.size()){ if (first) first = false; else cout << " "; cout << st.top(); st.pop(); } cout << endl; //system("pause");}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表