| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
java 1002 看看import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Map<String, String> m = new HashMap<String, String>();
m.put("A", "2");
m.put("B", "2");
m.put("C", "2");
m.put("D", "3");
m.put("E", "3");
m.put("F", "3");
m.put("G", "4");
m.put("H", "4");
m.put("I", "4");
m.put("J", "5");
m.put("K", "5");
m.put("L", "5");
m.put("M", "6");
m.put("N", "6");
m.put("O", "6");
m.put("P", "7");
m.put("R", "7");
m.put("S", "7");
m.put("T", "8");
m.put("U", "8");
m.put("V", "8");
m.put("W", "9");
m.put("X", "9");
m.put("Y", "9");
Scanner in = new Scanner(System.in);
int i = in.nextInt();
Map<String,Integer> r = new HashMap<String, Integer>();
while(i > 0) {
String str = in.next();
StringBuffer b = new StringBuffer();
for (int j = 0; j < str.length(); j ++) {
if (str.charAt(j) >= 'A' && str.charAt(j) < 'Z') {
String value = String.valueOf(str.charAt(j));
value = m.get(value);
if (value != null)
b.append(value);
}
if (str.charAt(j) >= '0' && str.charAt(j) <= '9') {
b.append(str.charAt(j));
}
if(b.length() == 3)
b.append('-');
}
String key = String.valueOf(b);
int c = 0;
if (r.get(key) != null)
c = r.get(key);
r.put(key, c + 1);
i--;
}
boolean flg = true;
List<Map.Entry<String, Integer>> infoIds = new ArrayList<Map.Entry<String, Integer>>(r.entrySet());
Collections.sort(infoIds, new Comparator<Map.Entry<String, Integer>>() {
public int compare(Map.Entry<String, Integer> o1,
Map.Entry<String, Integer> o2) {
return (o1.getKey().compareTo(o2.getKey()));
}
});
boolean pp = false;
for (int k = 0; k < infoIds.size(); k++) {
if (infoIds.get(k).getValue() > 1) {
if(pp) {
System.out.println();
}
System.out.print(infoIds.get(k).getKey() + " " + infoIds.get(k).getValue());
flg = false;
pp = true;
}
}
if (flg)
System.out.print("No duplicates");
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator