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

根据楼主的代码改编的Java代码,不知哪里出了问题

Posted by zpysr at 2014-03-01 23:09:53 on Problem 1002
In Reply To:感觉写得还行的代码,贴之: 916K 375MS G++ Posted by:Pcz at 2012-04-22 21:07:24
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static char[] s;
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        int n;
        n = in.nextInt();
        in.nextLine();
        int[] data = new int[n];
        for (int i = 0; i < n; i++) {
            s = in.nextLine().toCharArray();
            data[i] = Hash();
        }
        Arrays.sort(data);
        boolean p = false;
        n--;
        for (int i = 0, num = 1; i < n; i += num = 1) {
            while (i < n && data[i] == data[i + 1]) {{//将此循环try掉则为WA,否则为RE
                num++;
                i++;
            }
            if (num > 1) {
                System.out.printf("%03d-%04d %d\n", data[i] / 10000, data[i] % 10000, num);
                p = true;
            }
            if (!p) {
                System.out.printf("No duplicates. \n");
            }
        }
    }

    static int Hash() {
        int sum = 0;
        for (int i = 0, k = 0; k < 7; i++) {
            if (s[i] >= '0' && s[i] <= '9') {
                sum *= 10;
                k++;
                sum += (s[i] - '0');
            } else if (s[i] >= 'A' && s[i] < 'Z') {
                sum *= 10;
                k++;
                sum += ((s[i] - 'A' - (s[i] > 'Q' ? 1 : 0)) / 3 + 2);
            }
        }
        return sum;
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator