zoukankan      html  css  js  c++  java
  • 1005 Spell It Right

    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


    这是签到题目把?
    import java.util.*;
    
    public class Main{
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            String str = sc.next();
            sc.close();
            int res = 0;
            for(int i=0;i<str.length();i++)
                res+=Integer.valueOf(str.charAt(i)-48);
            String result = String.valueOf(res);
            for(int i=0;i<result.length();i++) {
                switch(result.charAt(i)) {
                case '0':
                    System.out.print("zero");
                    break;
                case '1':
                    System.out.print("one");
                    break;
                case '2':
                    System.out.print("two");
                    break;
                case '3':
                    System.out.print("three");
                    break;
                case '4':
                    System.out.print("four");
                    break;
                case '5':
                    System.out.print("five");
                    break;
                case '6':
                    System.out.print("six");
                    break;
                case '7':
                    System.out.print("seven");
                    break;
                case '8':
                    System.out.print("eight");
                    break;
                case '9':
                    System.out.print("nine");
                    break;
                }
                if(i!=result.length()-1) System.out.print(" ");
            }
        }
    }
  • 相关阅读:
    Java代码性能优化
    Kafka学习笔记(二、Kafka中的角色)
    CentOS 安装并运行Kafka
    CentOS ping name or service not known问题解决
    CentOS静态IP配置
    Kafka学习笔记(一、Kafka基础)
    sql去除中间和两边的空格
    实验二 数据更新与SQL简单查询
    实验一 完成订单数据库
    递归求P函数
  • 原文地址:https://www.cnblogs.com/godoforange/p/10903186.html
Copyright © 2011-2022 走看看