poj1002

import java.io.BufferedInputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;


public class poj1002 {

    char returnValue(char c){
        if(c<=67 && c>=65){
            return '2';
        }else if(c<=70 && c>=68){
            return '3';
        }else if(c<=73 && c>=71){
            return '4';
        }else if(c<=76 && c>=74){
            return '5';
        }else if(c<=79 && c>=77){
            return '6';
        }else if(c<=83 && c>=80){
            return '7';
        }else if(c<=86 && c>=84){
            return '8';
        }else if(c<=89 && c>=87){
            return '9';
        }else{
            return '0';
        }
    }
    String parse(String str) {
        String temp = "";
        for (int j = 0; j < str.length(); j++) {
            if (str.charAt(j) == '-') {
                continue;
            } else {
                char t = str.charAt(j);
                if (t >= '0' && t <= '9') {
                    temp += t;
                } else {
                    temp += returnValue(t);
                }
            }
        }
        return temp;
    }
    void solve(){
        Scanner cin=new Scanner(new BufferedInputStream(System.in));
        Map<String, Integer> m = new HashMap<String, Integer>();//jdk1.5


        int n=cin.nextInt();
        int i=1;
        while(n>=0) {

            String str=cin.nextLine();
            str=parse(str);

            Integer times = m.get(str);
            m.put(str, times == null ? 1 : times + 1);
            n=n-1;
        }
        Set<String> keys = new TreeSet<String>(m.keySet());
        boolean hasOutput = false;
        for (Iterator<String> it = keys.iterator(); it.hasNext();) {
            String key = it.next();
            if (m.get(key) > 1) {
                hasOutput = true;
                System.out.println(key.substring(0, 3) + "-"
                        + key.substring(3, 7) + " " + m.get(key));
            }
        }
        if (!hasOutput) {
            System.out.println("No duplicates.");
        }
    }
    public static void main(String[] args){ new poj1002().solve(); } } 

你可能感兴趣的:(java,poj)