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)
  • 相关阅读:
    React native 之 图标库ECharts的使用
    使用jquery给html标签加点击事件
    React native 之 async/await
    CSS布局之flexbox
    Swiper 的引入
    给浏览器设置一张背景图,并且拉动浏览器大小时图片不要被压缩变形
    境界的彼方_lduoj_bfs宽搜
    2021美国大学生数学建模大赛==ABCDEF+思路解析==
    3045 Lcm与Gcd构造
    对拍程序
  • 原文地址:https://www.cnblogs.com/h-hkai/p/12572936.html
Copyright © 2011-2022 走看看