Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## wa 求解

Posted by CatCoder at 2019-01-16 15:58:37 on Problem 1002
```import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Comparator;
import java.util.Collections;

/**
* @author lvgang
* @descript
* @time 2019-01-16 14:29
*/
public class Main {

public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int n = Integer.parseInt(scanner.nextLine());
//        Map<String,Integer> map = new HashMap<>(16);
//        List<String> keys = new ArrayList<>(16);
Map<String,Integer> map = new HashMap<String, Integer>(16);
List<String> keys = new ArrayList<String>(16);
while (n>0){
String value = scanner.nextLine();
/**
* 映射
*/
String code = value;
code=code.replaceAll("A","2");
code=code.replaceAll("B","2");
code=code.replaceAll("C","2");
code=code.replaceAll("D","3");
code=code.replaceAll("E","3");
code=code.replaceAll("F","3");
code=code.replaceAll("G","4");
code=code.replaceAll("H","4");
code=code.replaceAll("I","4");
code=code.replaceAll("J","5");
code=code.replaceAll("K","5");
code=code.replaceAll("L","5");
code=code.replaceAll("M","6");
code=code.replaceAll("N","6");
code=code.replaceAll("O","6");
code=code.replaceAll("P","7");
code=code.replaceAll("R","7");
code=code.replaceAll("S","7");
code=code.replaceAll("T","8");
code=code.replaceAll("U","8");
code=code.replaceAll("V","8");
code=code.replaceAll("W","9");
code=code.replaceAll("X","9");
code=code.replaceAll("Y","9");
/**
* 消除- 和 空格
*/
code=code.replaceAll("-","");
code=code.replaceAll(" ","");
/**
* 添加-
*/
if(code.length()==7){
n--;
//code=code.substring(0,2)+"-"+code.substring(2);
if(map.get(code)==null){
map.put(code,1);
}else {
map.put(code,map.get(code)+1);
if(map.get(code)==2){
}
}
}
}
Collections.sort(keys, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.compareTo(o2);
}
});
for(int i=0;i<keys.size();i++){
System.out.println(keys.get(i).substring(0,2)+"-"+keys.get(i).substring(2)+" "+map.get(keys.get(i)));
}

}
}```

Followed by: