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 (<= 10100).

    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 import java.util.*;
     2 public class Main {
     3     private static Map<Character,String> dig2Eng=new HashMap<Character,String>();
     4     static {
     5         dig2Eng.put('0',"zero");
     6         dig2Eng.put('1',"one");
     7         dig2Eng.put('2',"two");
     8         dig2Eng.put('3',"three");
     9         dig2Eng.put('4',"four");
    10         dig2Eng.put('5',"five");
    11         dig2Eng.put('6',"six");
    12         dig2Eng.put('7',"seven");
    13         dig2Eng.put('8',"eight");
    14         dig2Eng.put('9',"nine");
    15     }
    16     public static void main(String[] args) {
    17         Scanner in = new Scanner(System.in);
    18         String N=in.next();
    19         int sum=0;
    20         for(int i=0;i<N.length();i++){
    21             sum+=N.charAt(i)-'0';
    22         }
    23         String str=String.valueOf(sum);
    24         StringBuilder sb=new StringBuilder();
    25         for(int i=0;i<str.length();i++){
    26             sb.append(dig2Eng.get(str.charAt(i))+" ");
    27         }
    28         sb.deleteCharAt(sb.length()-1);
    29         System.out.println(sb.toString());
    30     }
    31 }
  • 相关阅读:
    二维莫队的一个细节
    错失AK良机的测试48T3 Walk
    枚举二进制子集
    又是一次值得纪念的考试
    测试46
    值得纪念的测试43
    点分治模板理解
    牛客多校第三场 G Removing Stones(分治+线段树)
    牛客多校第三场 F Planting Trees
    HDU6621 K-th Closest Distance HDU2019多校训练第四场 1008(主席树+二分)
  • 原文地址:https://www.cnblogs.com/BJUT-2010/p/5568174.html
Copyright © 2011-2022 走看看