Chinaunix首页 | 论坛 | 博客
  • 博客访问: 269948
  • 博文数量: 170
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1709
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-06 18:01
文章分类

全部博文(170)

文章存档

2016年(11)

2015年(130)

2014年(29)

分类: Java

2015-08-08 17:47:38

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
public class NumberFormat {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
ArrayList<String> list = new ArrayList<String>();
int t = Integer.parseInt(in.nextLine());
String map[] = new String[] { "ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu" };
String dec[] = new String[] { "wang","qian", "bai", "shi", "" };
for (int i = 0; i < t; i++) {
//使用nextInt去掉0
Integer a = in.nextInt();
list.add(a.toString());
}
for (int j = 0; j < list.size(); j++) {
String a = list.get(j);
StringBuilder result=new StringBuilder();
int flag = 0;
for (int k = 5; k >= 1; k--)
if (list.get(j).length() >= k) {
if (a.charAt(0) != '0') {
result.append(map[a.charAt(0) - '0'] + " " + dec[5 - k] + " ");
flag = 0;
} else if (flag == 0) {
result.append("ling ");
flag = 1;
}
a = a.substring(1, a.length());
}
//去掉最后的0
if(result.length()>5&&result.toString().substring(result.length()-5, result.length()-1).equals("ling"))
System.out.println(result.toString().substring(0,result.length()-5));
else
System.out.println(result.toString().substring(0, result.length()));
}
}
}
阅读(898) | 评论(0) | 转发(0) |
0

上一篇:Unique Paths

下一篇:Text Justification

给主人留下些什么吧!~~