Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
根据楼主的代码改编的Java代码,不知哪里出了问题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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator