1002 487-3279

import java.io.*;  
import java.util.*;  
public class Main {  
    static final int[] map = {  
        2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,0,7,7,8,8,8,9,9,9,0  
        };  
  
    public static void main(String[] args) throws Exception {  
        BufferedInputStream in = new BufferedInputStream(System.in, 20480);  
        byte[] buf = new byte[2048];  
        int n = in.read(buf, 0, 2048);  
        int caseCount = 0, pos = 0;  
        do {  
            if(buf[pos] >= '0' && buf[pos] <= '9') {  
                caseCount *= 10;  
                caseCount += (buf[pos]-'0');  
            }  
        } while(buf[pos++] != '\n');//得到输入项的个数  
          
        int[] phoneNum = new int[caseCount+1];  
        phoneNum[caseCount] = Integer.MAX_VALUE;  
        caseCount = 0;  
        int aPhoneNum = 0;  
        GetNum:do {  
            for(; pos < n; pos++) {  
                if(buf[pos] == '-')  
                    continue;  
                if(buf[pos] == '\n') {  
                    phoneNum[caseCount++] = aPhoneNum;  
                    if(caseCount >= phoneNum.length-1)  
                        break GetNum;  
                    aPhoneNum = 0;  
                    continue;  
                }  
  
                aPhoneNum *= 10;  
                if(buf[pos] >= '0' && buf[pos] <= '9')  
                    aPhoneNum += (buf[pos] - '0');  
                else if(buf[pos] >= 'A' && buf[pos] <= 'Z')  
                    aPhoneNum += map[buf[pos]-'A'];  
            }  
            pos = 0;  
        } while ((n = in.read(buf, 0, 2048)) != -1);  
  
        Arrays.sort(phoneNum);  
        boolean noDuplicates = true;  
        for(int i = 1, count = 1; i <= caseCount; i++) {  
            if(phoneNum[i] == phoneNum[i-1])  
                count++;  
            else {  
                if(count > 1) {  
                    System.out.printf("%03d-%04d %d%n", phoneNum[i-1]/10000,   
                        phoneNum[i-1]%10000, count);  
                    noDuplicates = false;  
                }  
                count = 1;  
            }  
        }  
        if(noDuplicates)  
            System.out.println("No duplicates.");  
    }  
}  

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