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

  • 相关阅读:
    idea 使用
    scala
    Java开发工具
    ActiveMQ基础
    Java 多线程实战
    Java 内部类和Lambda
    Spring 学习
    平滑重启php
    opcache
    redis的hscan命令
  • 原文地址:https://www.cnblogs.com/stormax/p/10939536.html
Copyright © 2011-2022 走看看