[PAT]1005. Spell It Right (20)@Java
2017-08-26 10:04
381 查看
1005. Spell It Right (20)
时间限制400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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
package go.jacob.day826; import java.util.Scanner; public class Demo1 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s=sc.nextLine(); int sum=0; for(int i=0;i<s.length();i++){ sum+=s.charAt(i)-'0'; } String res=sum+""; StringBuilder sb=new StringBuilder(); for(int i=0;i<res.length();i++){ switch (res.charAt(i)) { case '0': sb.append("zero "); break; case '1': sb.append("one "); break; case '2': sb.append("two "); break; case '3': sb.append("three "); break; case '4': sb.append("four "); break; case '5': sb.append("five "); break; case '6': sb.append("six "); break; case '7': sb.append("seven "); break; case '8': sb.append("eight "); break; default: sb.append("nine "); break; } } System.out.println(sb.toString().substring(0,sb.length()-1)); } }
相关文章推荐
- PAT-Java-1005-Spell It Right (20)
- 【PAT甲级】【C++】1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- [PAT]1005. Spell It Right (20)
- 【PAT Advanced Level】1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- PAT-1005 Spell It Right (20)
- PAT1005. Spell It Right (20)
- PAT-PAT (Advanced Level) Practise 1005. Spell It Right (20) (简单模拟题)【一星级】
- PAT (Advanced Level) Practise 1005 Spell It Right (20)
- PAT-A-1005. Spell It Right (20)
- PAT-A 1005. Spell It Right (20)
- PAT_A 1005. Spell It Right (20)
- 【PAT】【Advanced Level】1005. Spell It Right (20)
- Python 实现Pat 1005. Spell It Right (20)
- PAT Advanced 1005. Spell It Right (20) (C语言实现)
- PAT 1005. Spell It Right (20)
- 【PAT】1005. Spell It Right (20)
- [PAT]1005. Spell It Right (20)