Skip to content

1005 Spell It Right

Statement

Metadata

  • 作者: CHEN, Yue
  • 单位: 浙江大学
  • 代码长度限制: 16 KB
  • 时间限制: 400 ms
  • 内存限制: 64 MB

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 (\le 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

Solution

#include <ctype.h>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss;

const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-30;

const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;

string tran(int x) {
    string s = "";
    if (x == 0)
        return "0";
    while (x) {
        s += x % 10 + '0';
        x /= 10;
    }
    return s;
}

int main() {
    string s;
    cin >> s;
    int len = s.size();
    int sum = 0;
    for (int i = 0; i < len; i++) sum += s[i] - '0';
    map<char, string> m;
    m['0'] = "zero";
    m['1'] = "one";
    m['2'] = "two";
    m['3'] = "three";
    m['4'] = "four";
    m['5'] = "five";
    m['6'] = "six";
    m['7'] = "seven";
    m['8'] = "eight";
    m['9'] = "nine";
    string ans = tran(sum);
    len = ans.size();
    for (int i = len - 1; i >= 0; i--) {
        if (i != len - 1)
            printf(" ");
        cout << m[ans[i]];
    }
    cout << endl;
}

Last update: May 4, 2022
Back to top