Trang

Chủ Nhật, 2 tháng 1, 2011

1161. 487-3279

import java.io.*;
import java.util.*;

public class Main {

    /**
     * http://acm.tju.edu.cn/toj/showp1161.html
     * @author hunglee
     */
    private static String letter = "ABCDEFGHIJKLMNOPRSTUVWXY";
    public static void main(String[] args) throws IOException {

        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        int n;
        int[] a = new int[10000000];
        Integer i;
        n = in.nextInt();
        in.nextLine();
        while (n-- > 0) {
            i = convert(in.nextLine());
            a[i]++;
        }
        n = 0;
        for (i = 0; i < 10000000; i++)
            if (a[i] > 1) {
                n++;
                out.print(String.format("%03d-%04d", i / 10000, i % 10000));
                out.print(" ");
                out.println(a[i]);
            }
        if (n == 0)
            out.println("No duplicates.");
        out.flush();
    }
    
    protected static int convert(String s) {
        int res = 0;
        
        for (int i = 0; i < s.length(); i++) {
            if (Character.isDigit(s.charAt(i)))
                res = 10 * res + (s.charAt(i) - '0');
            else if (Character.isUpperCase(s.charAt(i)))
                res = 10 * res + (2 + letter.indexOf(s.charAt(i)) / 3);
        }
        return res;
        //return String.format("%03d-%04d", res / 10000, res % 10000);
    }

}

Không có nhận xét nào:

Đăng nhận xét