POJ1002

import java.util.*;
public class Main{
    public static void main(String args[]) {
        Scanner cin = new Scanner(System.in);
        int count = cin.nextInt();
        List<String> listString = new ArrayList<String>(count);
        while (count > 0) {
            listString.add(cin.next());
            count--;
        }
        Map<String, Integer> mnum = new TreeMap<String, Integer>();
        for (String str : listString) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0, size = str.length(); i < size; i++) {
                if (sb.length() == 3) {
                    sb.append("-");
                }
                char ch = str.charAt(i);
                if (Character.isDigit(ch)) {
                    sb.append(str.charAt(i));
                    continue;
                }
                switch (ch) {
                    case 'A':
                    case 'B':
                    case 'C':
                        sb.append("2");
                        break;
                    case 'D':
                    case 'E':
                    case 'F':
                        sb.append("3");
                        break;
                    case 'G':
                    case 'H':
                    case 'I':
                        sb.append("4");
                        break;
                    case 'J':
                    case 'K':
                    case 'L':
                        sb.append("5");
                        break;
                    case 'M':
                    case 'N':
                    case 'O':
                        sb.append("6");
                        break;
                    case 'P':
                    case 'R':
                    case 'S':
                        sb.append("7");
                        break;
                    case 'T':
                    case 'U':
                    case 'V':
                        sb.append("8");
                        break;
                    case 'W':
                    case 'X':
                    case 'Y':
                        sb.append("9");
                        break;
                    default:
                        break;
                }
            }
            Integer numCount = mnum.get(sb.toString());
            if (numCount == null) {
                mnum.put(sb.toString(), 1);
            } else {
                mnum.put(sb.toString(), numCount + 1);
            }
        }
        boolean flag = true;
        for (String key : mnum.keySet()) {
            Integer numCount = mnum.get(key);
            if (numCount > 1) {
                flag = false;
                System.out.println(key + " " + numCount);
            }
        }
        if (flag) {
            System.out.println("No duplicates. ");
        }
    }
}

你可能感兴趣的:(poj)