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

    题意:

    输入一个数字,将其各位相加,然后将相加的和的各位用英文输出。

    Code:

    #include <iostream>
    #include <string>
    
    using namespace std;
    
    void digit_to_En(int x)
    {
        switch (x)
        {
        case 1:
            cout << "one";
            break;
        case 2:
            cout << "two";
            break;
        case 3:
            cout << "three";
            break;
        case 4:
            cout << "four";
            break;
        case 5:
            cout << "five";
            break;
        case 6:
            cout << "six"; 
            break;
        case 7 : 
            cout << "seven";
            break;
        case 8:
            cout << "eight";
            break;
        case 9:
            cout << "nine";
            break;
        case 0:
            cout << "zero";
            break;
        default:
            break;
        }
    
        return ;
    }
    
    int main()
    {
    
        string num;
        cin >> num;
    
        int first_digit = num[0] - '0';
    
        long sum = 0;
        for (int i = 0; i < num.length(); ++i)
        {
            int n = num[i] - '0';
            sum += n;
        }
    
        string sum_str = to_string(sum);
    
        digit_to_En(sum_str[0] - '0');
        for (int i = 1; i < sum_str.length(); ++i) 
        {
            int n = sum_str[i] - '0';
            cout << " ";
            digit_to_En(n);
        }
    
        return 0;
    }
    

      

    注意:英文字母不要写错。

    永远渴望,大智若愚(stay hungry, stay foolish)
  • 相关阅读:
    Python的包管理工具Pip
    C语言移位运算符
    malloc函数具体解释
    HDU
    Java中Scanner的使用方法
    DOS call 中的%cd%,当前文件夹演示
    没有找到MSVCR100.dll解决方法
    什么是响应式表格(响应式表格和普通表格的区别)
    Redis和Memcache和MongoDB简介及区别分析(整理)
    GIT将本地项目上传到Github(两种简单、方便的方法)
  • 原文地址:https://www.cnblogs.com/h-hkai/p/12572936.html
Copyright © 2011-2022 走看看