| | |
ACMICPC Contest Scoring
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Dec 2007
Posts: 4
Reputation:
Solved Threads: 0
java Syntax (Toggle Plain Text)
import java.io.*; public class ACMICPCContestScoring { public static void main(String[] args) throws IOException { BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in)); BufferedReader br = new BufferedReader(new FileReader (" ")); String s = br.readLine(); String[] array1 = s.split(" "); int numberOfTeams = Integer.parseInt(array1[0]); int numberOfProblems = Integer.parseInt(array1[1]); String[] timeStarted = array1[2].split(":"); String[][] arrayTeamsStatusForProblems = new String[numberOfTeams][numberOfProblems]; int[] arrayTeamsStatusForTimePenalty = new int[numberOfTeams]; int[][] arrayTeamsStatusForTimePenaltyTemp = new int[numberOfTeams][numberOfProblems]; for (int i = 0; i < numberOfTeams; i++) { for (int j = 0; j < numberOfProblems; j++) { arrayTeamsStatusForProblems[i][j] = "U"; } } int[] numberOfProblemAttempts = new int[numberOfProblems]; int[] numberOfAcceptedProblems = new int[numberOfProblems]; int[] numberOfRejectedProblems = new int[numberOfProblems]; int[][] arrayTeamsTimeOfLastAcceptedRun = new int[numberOfTeams][2]; while (true) { String str = br.readLine(); if (str != null) { String[] arrayStr = str.split(" "); arrayTeamsStatusForProblems[Integer.parseInt(arrayStr[1]) - 1][Integer.parseInt(arrayStr[2]) - 1] = arrayStr[3]; if (arrayStr[3].equals("Y")) { numberOfAcceptedProblems[Integer.parseInt(arrayStr[2]) - 1]++; String[] timeSolved = arrayStr[0].split(":"); arrayTeamsStatusForTimePenalty[Integer.parseInt(arrayStr[1]) - 1] += ((Integer.parseInt(timeSolved[0]) - Integer.parseInt(timeStarted[0])) * 60) + (Integer.parseInt(timeSolved[1]) - Integer.parseInt(timeStarted[1])); // ADD THE NUMBER OF ELAPSED MINUTES SINCE THE START OF THE CONTEST if (arrayTeamsStatusForTimePenaltyTemp[Integer.parseInt(arrayStr[1]) - 1][Integer.parseInt(arrayStr[2]) - 1] > 0) { arrayTeamsStatusForTimePenalty[Integer.parseInt(arrayStr[1]) - 1] += arrayTeamsStatusForTimePenaltyTemp[Integer.parseInt(arrayStr[1]) - 1][Integer.parseInt(arrayStr[2]) - 1]; // ADD THE PREVIOUS COUNTED PENALTY POINTS FROM THE TEMP ARRAY } arrayTeamsTimeOfLastAcceptedRun[Integer.parseInt(arrayStr[1]) - 1][0] = Integer.parseInt(timeSolved[0]); arrayTeamsTimeOfLastAcceptedRun[Integer.parseInt(arrayStr[1]) - 1][1] = Integer.parseInt(timeSolved[1]); } else if (arrayStr[3].equals("N")) { numberOfRejectedProblems[Integer.parseInt(arrayStr[2]) - 1]++; arrayTeamsStatusForTimePenaltyTemp[Integer.parseInt(arrayStr[1]) - 1][Integer.parseInt(arrayStr[2]) - 1] += 20; } numberOfProblemAttempts[Integer.parseInt(arrayStr[2]) - 1]++; } else { break; } } br.close(); System.out.println(); int[] numberOfSolvedProblems = new int[numberOfTeams]; for (int i = 0; i < numberOfSolvedProblems.length; i++) { int ctrSolvedProblems = 0; for (int j = 0; j < numberOfProblems; j++) { if (arrayTeamsStatusForProblems[i][j].equals("Y")) { ctrSolvedProblems++; } } numberOfSolvedProblems[i] = ctrSolvedProblems; int[] arrayRankOfTeams = new int[numberOfTeams]; for (int o = 0; o < numberOfTeams; o++) { arrayRankOfTeams[i] = i + 1; } for (int k = 0; k < numberOfTeams - 1; k++) { for (int j = i + 1; j < numberOfTeams; j++) { if (numberOfSolvedProblems[i] < numberOfSolvedProblems[j]) // FIRST PHASE: ACCORDING TO THE NUMBER OF PROBLEMS SOLVED { int temp = numberOfSolvedProblems[i]; numberOfSolvedProblems[i] = numberOfSolvedProblems[j]; numberOfSolvedProblems[j] = temp; int temp2 = arrayTeamsStatusForTimePenalty[i]; arrayTeamsStatusForTimePenalty[i] = arrayTeamsStatusForTimePenalty[j]; arrayTeamsStatusForTimePenalty[j] = temp2; int temp3 = arrayRankOfTeams[i]; arrayRankOfTeams[i] = arrayRankOfTeams[j]; arrayRankOfTeams[j] = temp3; } else if (numberOfSolvedProblems[i] == numberOfSolvedProblems[j]) { if (arrayTeamsStatusForTimePenalty[i] > arrayTeamsStatusForTimePenalty[j]) { int temp = numberOfSolvedProblems[i]; numberOfSolvedProblems[i] = numberOfSolvedProblems[j]; numberOfSolvedProblems[j] = temp; int temp2 = arrayTeamsStatusForTimePenalty[i]; arrayTeamsStatusForTimePenalty[i] = arrayTeamsStatusForTimePenalty[j]; arrayTeamsStatusForTimePenalty[j] = temp2; int temp3 = arrayRankOfTeams[i]; arrayRankOfTeams[i] = arrayRankOfTeams[j]; arrayRankOfTeams[j] = temp3; } else if (arrayTeamsStatusForTimePenalty[i] > 0 && arrayTeamsStatusForTimePenalty[i] == arrayTeamsStatusForTimePenalty[j]) { if (arrayTeamsTimeOfLastAcceptedRun[i][0] < arrayTeamsTimeOfLastAcceptedRun[j][0]) { int temp = numberOfSolvedProblems[i]; numberOfSolvedProblems[i] = numberOfSolvedProblems[j]; numberOfSolvedProblems[j] = temp; int temp2 = arrayTeamsStatusForTimePenalty[i]; arrayTeamsStatusForTimePenalty[i] = arrayTeamsStatusForTimePenalty[j]; arrayTeamsStatusForTimePenalty[j] = temp2; int temp3 = arrayRankOfTeams[i]; arrayRankOfTeams[i] = arrayRankOfTeams[j]; arrayRankOfTeams[j] = temp3; } else if (arrayTeamsTimeOfLastAcceptedRun[i][0] == arrayTeamsTimeOfLastAcceptedRun[j][0] && arrayTeamsTimeOfLastAcceptedRun[i][1] < arrayTeamsTimeOfLastAcceptedRun[j][1]) { int temp = numberOfSolvedProblems[i]; numberOfSolvedProblems[i] = numberOfSolvedProblems[j]; numberOfSolvedProblems[j] = temp; int temp2 = arrayTeamsStatusForTimePenalty[i]; arrayTeamsStatusForTimePenalty[i] = arrayTeamsStatusForTimePenalty[j]; arrayTeamsStatusForTimePenalty[j] = temp2; int temp3 = arrayRankOfTeams[i]; arrayRankOfTeams[i] = arrayRankOfTeams[j]; arrayRankOfTeams[j] = temp3; } } else { if (i > j) { int temp3 = arrayRankOfTeams[i]; arrayRankOfTeams[i] = arrayRankOfTeams[j]; arrayRankOfTeams[j] = temp3; } } } } } // OUTPUT PrintWriter pw = new PrintWriter(new FileWriter("renjei.txt")); pw.println("CONTEST RESULTS"); pw.printf("%10s", "RANK"); pw.printf("%10s", "TEAM"); pw.printf("%10s", "SOLVED"); pw.printf("%10s%n", "PENALTY"); for (int a = 0, rank = 1; a < numberOfTeams; a++, rank++) { pw.printf("%10s", rank); pw.printf("%10s", arrayRankOfTeams[i]); pw.printf("%10s", numberOfSolvedProblems[i]); pw.printf("%10s%n", arrayTeamsStatusForTimePenalty[i]); if (i + 1 < numberOfTeams && numberOfSolvedProblems[i] == numberOfSolvedProblems[i + 1] && arrayTeamsStatusForTimePenalty[i] == arrayTeamsStatusForTimePenalty[i + 1]) { rank--; } else { rank = i + 1; } } pw.println(); pw.println("PROBLEM SOLUTION STATISTICS"); pw.printf("%10s", "PROBLEM"); pw.printf("%10s", "ATTEMPTS"); pw.printf("%10s", "ACCEPTED"); pw.printf("%10s%n", "REJECTED"); for (int n = 0; n < numberOfProblems; n++) { pw.printf("%10d", (i + 1)); pw.printf("%10d", numberOfProblemAttempts[i]); pw.printf("%10d", numberOfAcceptedProblems[i]); pw.printf("%10d%n", numberOfRejectedProblems[i]); } pw.close(); System.out.println(); for (int m = 0; m < numberOfTeams; m++) { System.out.print("Team #" + (i + 1) + ": "); for (int j = 0; j < numberOfProblems; j++) { System.out.print(arrayTeamsStatusForProblems[i][j] + ","); } System.out.println(); } System.out.println(); for (int h = 0; h < numberOfTeams; h++) { System.out.println("Team #" + (i + 1) + " solved " + numberOfSolvedProblems[i] + " problems."); } System.out.println(); for (int g = 0; g < numberOfTeams; g++) { System.out.print("Total Time Penalty of Team #" + (i + 1) + ": " + arrayTeamsStatusForTimePenalty[i]); System.out.println(); } System.out.println(); for (int f = 0; f < numberOfTeams; f++) { System.out.print("Rank #" + (i + 1) + ": " + arrayRankOfTeams[i]); System.out.println(); } } } }
Last edited by ~s.o.s~; Dec 16th, 2007 at 8:54 am. Reason: Added code tags, learn to use them.
And? What is this for? What is it suppossed to be, other than a procedural program masquerading as a Java program?
Did you have a question? Or did you simply want to show the world that you
1) Have no idea what OOP is
2) Have no idea how to post code to a forum
Did you have a question? Or did you simply want to show the world that you
1) Have no idea what OOP is
2) Have no idea how to post code to a forum
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Maybe. If you post the code correctly (use code tags) and actually ask a specific question, and give detailed explanations of what, up to this point, is not working as it should, and what the difference is.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
And I have no idea what you mean with that statement.
Is this your code? If so, what problem are you having with it? If not, ask the entity from which you received the code.
Is this your code? If so, what problem are you having with it? If not, ask the entity from which you received the code.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Other Threads in the Java Forum
- Previous Thread: Multiple Windows in Java
- Next Thread: pls help me my homework(%30) so important pls if you know these problems help me plss
| Thread Tools | Search this Thread |
Tag cloud for Java
affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth businessintelligence chat class classes client code component database desktop draw ebook eclipse encode equation error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer intersect j2me java javaexcel javaprojects jmf jni jpanel julia linked linux list loop mac main map method methods mobile netbeans newbie number online open-source oracle parameter print problem program programming project properties recursion reference replaysolutions rotatetext scanner score screen scrollbar server set size sms socket sort sql string superclass swing template test threads time tree windows working xstream






