poj 1002 算是解决了 想起来葵花宝典
错在没有看清题 题目要求打印出出现超过一次的号码
与其骂娘 不如踏踏实时的再看 实在不行就放弃呗
import java.util.*;
class Counter {
int i = 1;
public String toString() {
return Integer.toString(i);
}
}
class P1002x {
public static void main(String args[]){
ArrayList al=new ArrayList();
LinkedHashMap numbers = new LinkedHashMap();
LinkedHashMap ht=sumOut(numbers);
Iterator it = ht.keySet().iterator();
while (it.hasNext()) {
Object o = it.next();
al.add(o);
//System.out.print(o+" ");
//System.out.println(ht.get(o));
}
Object array[]=new Object[al.size()];
//for(int i=0;i<al.size();i++){
array= al.toArray();
//}
Arrays.sort(array);
boolean flag=false;
int ma=0;
for(int i=0;i<al.size();i++){
ma=((Counter)ht.get(array[i])).i;
if(ma>1){
flag=true;
}
if(ma>1){
System.out.print(array[i]+" ");
System.out.println(ht.get(array[i]));
}
}
if(!flag){
System.out.println("No duplicates.");
}
}
//转换 将输入 转化成标准输出
public static LinkedHashMap sumOut(LinkedHashMap ht){
Scanner scan=new Scanner(System.in);
int time=scan.nextInt();//获取次数
for(int i=0;i<time;i++){
String in=scan.next();//逐行获取
String out=transform(in);//转换完成
//hashtable 加入
if(ht.containsKey(out)){
((Counter)(ht.get(out))).i++;
}
else{
ht.put(out, new Counter());
}
}
return ht;
}
public static String transform(String in){
String out="";
int count=0;
char tempor;
for(int i=0;i<in.length();i++){
tempor=in.charAt(i);
if(tempor=='-') continue;
count++;
if(count==4){
out=out+'-';
}
out=out+(mapping(tempor));
//System.out.println("已经加上了一个字母 : "+tempor);
//System.out.println("out变为 : "+out);
}
//System.out.println("结果是 : "+out);
return out;
}
//将输入字母 转化成标准输出的字母
public static int mapping(char c){
switch(c){
case 'A':
case 'B':
case 'C': return 2;
case 'D':
case 'E':
case 'F':return 3;
case 'G':
case 'H':
case 'I':return 4;
case 'J':
case 'K':
case 'L':return 5;
case 'M':
case 'N':
case 'O':return 6;
case 'P':
case 'R':
case 'S':return 7;
case 'T':
case 'U':
case 'V':return 8;
case 'W':
case 'X':
case 'Y':return 9;
case '1':return 1;
default:
return c-48;
}
}
}