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;
    }
    感想:
    今天状态实属差劲,做数学做的像个铁憨憨,写个博客水一水。很明显,这是个水题,但一次没做对,真是个小老弟。

  • 相关阅读:
    linux 学习笔记
    linux 子系统折腾记 (三)
    linux子系统折腾记 (二)
    windows linux 子系统折腾记
    会计学习笔记(非专业)
    linux 大冒险
    coreRT 和 Native 编译netcore AOT程序
    dotnet core如何编译exe
    win10的hyper-v共享文件夹
    packagereference 里面的资产是怎么回事?
  • 原文地址:https://www.cnblogs.com/stormax/p/10939536.html
Copyright © 2011-2022 走看看