zoukankan      html  css  js  c++  java
  • 1005 Spell It Right (20 分)

    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
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 const int maxn = 1e6+7;
     5 char s[maxn];
     6 int a[maxn];
     7 
     8 void sea(int x){
     9     switch(x){
    10     case 0:
    11         cout << "zero" ; break;
    12     case 1:
    13         cout << "one" ; break;
    14     case 2:
    15         cout << "two" ; break;
    16     case 3:
    17         cout << "three" ; break;
    18     case 4:
    19         cout << "four" ; break;
    20     case 5:
    21         cout << "five" ; break;
    22     case 6:
    23         cout << "six" ; break;
    24     case 7:
    25         cout << "seven" ; break;
    26     case 8:
    27         cout << "eight" ; break;
    28     case 9:
    29         cout << "nine" ; break;
    30     }
    31 }
    32 
    33 int main(){
    34     cin >> s;
    35     int ans = 0;
    36     int len = strlen(s);
    37     for(int i = 0;i < len;i++){
    38         ans += s[i] - '0';
    39     }
    40     int ll = 0;
    41     while(ans){
    42         int x = ans%10;
    43         ans /= 10;
    44         a[ll++] = x;
    45     }
    46     for(int j = ll-1;j > 0;j--){
    47         sea(a[j]);
    48         cout <<" ";
    49     }
    50     sea(a[0]);
    51     return 0;
    52 }
  • 相关阅读:
    设计模式03
    设计模式02
    设计模式01
    HTTP
    C++ 编程学习(六) 函数
    C++编程学习(五) C++ 存储类
    C++编程学习(四)声明/枚举
    ROS常见问题(一) 安装ROS时sudo rosdep init指令报错 最全解决方法
    ROS常用命令或经常碰到的问题
    Ubuntu16.04 在Windows10 系统下的安装(双系统)
  • 原文地址:https://www.cnblogs.com/ouyang_wsgwz/p/10104764.html
Copyright © 2011-2022 走看看