import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
/**
* Created by chentao on 16-9-23.
* 电话号码分身
时间限制:C/C++语言 1000MS;其他语言 3000MS
内存限制:C/C++语言 65536KB;其他语言 589824KB
题目描述:
继MIUI8推出手机分身功能之后,MIUI9计划推出一个电话号码分身的功能:首先将电话号码中的每个数字加上8取个位,然后使用对应的大写字母代替
("ZERO", "ONE", "TWO", "THREE", "FOUR",
"FIVE", "SIX", "SEVEN", "EIGHT", "NINE"),
然后随机打乱这些字母,所生成的字符串即为电话号码对应的分身。
输入
第一行是一个整数T(1<=T<=100)表示测试样例数;接下来T行,每行给定一个分身后的电话号码的分身(长度在3到10000之间)。
输出
输出T行,分别对应输入中每行字符串对应的分身前的最小电话号码(允许前导0)。
样例输入
4
EIGHT
ZEROTWOONE
OHWETENRTEO
OHEWTIEGTHENRTEO
样例输出
0
234
345
0345
*/
public class 电话号码分身 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()){
int n = in.nextInt();
for (int i = 0; i < n; i++) {
String str = in.next();
int[] data = getNums(str);
for (int j = 0; j < data.length; j++) {
System.out.print(data[j]);
if (j == data.length - 1) System.out.println();
}
}
}
}
private static int[] getNums(String str) {
char[] ch = str.toCharArray();
ArrayList<Character> list = new ArrayList<>();
for (int i = 0; i < ch.length; i++) {
list.add(ch[i]);
}
ArrayList<Integer> result = new ArrayList<>();
//2
while (list.contains('W')){
list.remove((Character)'T');
list.remove((Character)'W');
list.remove((Character)'O');
result.add(2);
}
//4
while (list.contains('U')){
list.remove((Character)'F');
list.remove((Character)'O');
list.remove((Character)'U');
list.remove((Character)'R');
result.add(4);
}
//6
while (list.contains('X')){
list.remove((Character)'S');
list.remove((Character)'I');
list.remove((Character)'X');
result.add(6);
}
//8
while (list.contains('G')){
list.remove((Character)'E');
list.remove((Character)'I');
list.remove((Character)'G');
list.remove((Character)'H');
list.remove((Character)'T');
result.add(8);
}
//5
while (list.contains('F')){
list.remove((Character)'F');
list.remove((Character)'I');
list.remove((Character)'V');
list.remove((Character)'E');
result.add(5);
}
//7
while (list.contains('S')){
list.remove((Character)'S');
list.remove((Character)'E');
list.remove((Character)'V');
list.remove((Character)'E');
list.remove((Character)'N');
result.add(7);
}
//3
while (list.contains('H')){
list.remove((Character)'T');
list.remove((Character)'H');
list.remove((Character)'R');
list.remove((Character)'E');
list.remove((Character)'E');
result.add(3);
}
//0
while (list.contains('Z')){
list.remove((Character)'Z');
list.remove((Character)'E');
list.remove((Character)'R');
list.remove((Character)'O');
result.add(0);
}
//1
while (list.contains('O')){
list.remove((Character)'O');
list.remove((Character)'N');
list.remove((Character)'E');
result.add(1);
}
//9
while (list.contains('I')){
list.remove((Character)'N');
list.remove((Character)'I');
list.remove((Character)'N');
list.remove((Character)'E');
result.add(9);
}
int[] data = new int[result.size()];
for (int i = 0; i < result.size(); i++) {
if (result.get(i) == 8) data[i] = 0;
else data[i] = result.get(i)+10-8;
}
Arrays.sort(data);
return data;
}
}
这代码错哪里呢?