import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
class Main {
public static void main(String args[]) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
// a string buffer to show ours final result
// A thread-safe, mutable sequence of characters.
// A string buffer is like a String, but can be modified.
// At any point in time it contains some particular sequence of
// characters,
// but the length and content of the sequence can be changed through
// certain
// method calls.
StringBuffer sb = new StringBuffer("");
int cases = Integer.parseInt(in.readLine());
// read the empty line
in.readLine();
// evaluate each case
for (int i = 0; i < cases; ++i) {
// add a new line to string buffer after first line
if (i > 0) {
sb.append("\n");
}
// create object refernce array for all teams
Teams[] teams = new Teams[101];
// initialise all Teams object
for (int j = 0, length = teams.length; j < length; ++j) {
teams[j] = new Teams(j);
}
// a 2d array of int and boolean for mapping total attempts
// to solve a particular question and to know whther a question is
// finally solved by a particular team respectiviely
int ttlAttemptPerQstByTeam[][] = new int[101][10];
boolean questionSolvedByTeam[][] = new boolean[101][10];
String m = "";
// create a boolean array of serial numbers
// to know which team particiapted
boolean[] teamParticipated = new boolean[101];
while ((m = in.readLine()) != null) {
if (m.trim().equals("")) {
break;
}
String[] details = m.split(" ");
int teamNo = Integer.parseInt(details[0]);
teamParticipated[teamNo] = true;
int problem = Integer.parseInt(details[1]);
int penalty = Integer.parseInt(details[2]);
String stat = details[3];
// default value of boolean is false , #SnikItz
if (!questionSolvedByTeam[teamNo][problem]) {
// if the stat is correct "C"
if (stat.equals("C")) {
int currPenality = ttlAttemptPerQstByTeam[teamNo][problem]
* 20 + penalty;
questionSolvedByTeam[teamNo][problem] = true;
teams[teamNo].addsolved();
teams[teamNo].addPenalty(currPenality);
} else if (stat.equals("I")) {
ttlAttemptPerQstByTeam[teamNo][problem]++;
}
}
}
Arrays.sort(teams);
for (int j = 0 , length = teams.length; j < length; ++j) {
int num = teams[j].getTeamNumber();
if ( teamParticipated[num]) {
sb.append(teams[j].getTeamNumber()).append(" ").append(teams[j].getSolved()).append(" ").append(teams[j].getPenalty());
sb.append("\n");
}
}
}
System.out.print(sb);
}
}
class Teams implements Comparable<Teams> {
private int teamNumber, solved, penalty;
public Teams(int n) {
this.teamNumber = n;
this.solved = this.penalty = 0;
}
public int getPenalty() {
return this.penalty;
}
public void setPenalty(int penalty) {
this.penalty = penalty;
}
public void addPenalty(int penalty) {
this.penalty += penalty;
}
public void addsolved() {
this.solved++;
}
public int getSolved() {
return solved;
}
public void setSolved(int solved) {
this.solved = solved;
}
public int getTeamNumber() {
return teamNumber;
}
public void setTeamN(int teamN) {
this.teamNumber = teamN;
}
// Compares this object with the specified object for order.
// Returns a negative integer, zero, or a positive integer as this
// object
// is less than, equal to, or greater than the specified object.
@Override
public int compareTo(Teams o) {
if (this.solved > o.getSolved())
return -1;
else if (this.solved < o.getSolved())
return 1;
// if theres a tie in total correct solved
// check for least penalty time
else {
if (this.penalty > o.getPenalty())
return 1;
else {
if (this.teamNumber > o.getTeamNumber()) {
return 1;
} else {
return -1;
}
}
}
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
class Main {
public static void main(String args[]) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
// a string buffer to show ours final result
// A thread-safe, mutable sequence of characters.
// A string buffer is like a String, but can be modified.
// At any point in time it contains some particular sequence of
// characters,
// but the length and content of the sequence can be changed through
// certain
// method calls.
StringBuffer sb = new StringBuffer("");
int cases = Integer.parseInt(in.readLine());
// read the empty line
in.readLine();
// evaluate each case
for (int i = 0; i < cases; ++i) {
// add a new line to string buffer after first line
if (i > 0) {
sb.append("\n");
}
// create object refernce array for all teams
Teams[] teams = new Teams[101];
// initialise all Teams object
for (int j = 0, length = teams.length; j < length; ++j) {
teams[j] = new Teams(j);
}
// a 2d array of int and boolean for mapping total attempts
// to solve a particular question and to know whther a question is
// finally solved by a particular team respectiviely
int ttlAttemptPerQstByTeam[][] = new int[101][10];
boolean questionSolvedByTeam[][] = new boolean[101][10];
String m = "";
// create a boolean array of serial numbers
// to know which team particiapted
boolean[] teamParticipated = new boolean[101];
while ((m = in.readLine()) != null) {
if (m.trim().equals("")) {
break;
}
String[] details = m.split(" ");
int teamNo = Integer.parseInt(details[0]);
teamParticipated[teamNo] = true;
int problem = Integer.parseInt(details[1]);
int penalty = Integer.parseInt(details[2]);
String stat = details[3];
// default value of boolean is false , #SnikItz
if (!questionSolvedByTeam[teamNo][problem]) {
// if the stat is correct "C"
if (stat.equals("C")) {
int currPenality = ttlAttemptPerQstByTeam[teamNo][problem]
* 20 + penalty;
questionSolvedByTeam[teamNo][problem] = true;
teams[teamNo].addsolved();
teams[teamNo].addPenalty(currPenality);
} else if (stat.equals("I")) {
ttlAttemptPerQstByTeam[teamNo][problem]++;
}
}
}
Arrays.sort(teams);
for (int j = 0 , length = teams.length; j < length; ++j) {
int num = teams[j].getTeamNumber();
if ( teamParticipated[num]) {
sb.append(teams[j].getTeamNumber()).append(" ").append(teams[j].getSolved()).append(" ").append(teams[j].getPenalty());
sb.append("\n");
}
}
}
System.out.print(sb);
}
}
class Teams implements Comparable<Teams> {
private int teamNumber, solved, penalty;
public Teams(int n) {
this.teamNumber = n;
this.solved = this.penalty = 0;
}
public int getPenalty() {
return this.penalty;
}
public void setPenalty(int penalty) {
this.penalty = penalty;
}
public void addPenalty(int penalty) {
this.penalty += penalty;
}
public void addsolved() {
this.solved++;
}
public int getSolved() {
return solved;
}
public void setSolved(int solved) {
this.solved = solved;
}
public int getTeamNumber() {
return teamNumber;
}
public void setTeamN(int teamN) {
this.teamNumber = teamN;
}
// Compares this object with the specified object for order.
// Returns a negative integer, zero, or a positive integer as this
// object
// is less than, equal to, or greater than the specified object.
@Override
public int compareTo(Teams o) {
if (this.solved > o.getSolved())
return -1;
else if (this.solved < o.getSolved())
return 1;
// if theres a tie in total correct solved
// check for least penalty time
else {
if (this.penalty > o.getPenalty())
return 1;
else {
if (this.teamNumber > o.getTeamNumber()) {
return 1;
} else {
return -1;
}
}
}
}
}
No comments:
Post a Comment