zoukankan      html  css  js  c++  java
  • 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 (≤).

    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

    #include <iostream>
    #include <string>
    #include <string.h>
    #include <stdio.h>
    using namespace std;
    int main()
    {
        string name[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
        char num[105];
        scanf("%s", num);
        int sum = 0;
        for (int i = 0; num[i] != ''; i++)
        {
            sum += num[i] - '0';
        }
        if(sum == 0)
        {
            cout << "zero";
            return 0;
        }
        int stack[10], top = 0;
        while (sum)
        {
            stack[top++] = sum % 10;
            sum /= 10;
        }
            cout << name[stack[--top]];
        while (top)
        {
            cout << " " << name[stack[--top]];
        }
        return 0;
    }
    感想:
    今天状态实属差劲,做数学做的像个铁憨憨,写个博客水一水。很明显,这是个水题,但一次没做对,真是个小老弟。

  • 相关阅读:
    构建之法(一)
    大二下周总结十四
    寒假学习报告03
    寒假学习报告02
    2019春季学期个人总结
    2019春学习进度报告(第十六周)
    计算英语最长单词连
    2019春学习进度报告(第十五周)
    用户体验评价
    2019春学习进度报告(第十四周)
  • 原文地址:https://www.cnblogs.com/stormax/p/10939536.html
Copyright © 2011-2022 走看看