Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Do you remember how this contest is going to be scored? For every problem judged

ID: 3706851 • Letter: D

Question

Do you remember how this contest is going to be scored? For every problem judged correct, you get
one penalty point for every minute from the beginning of the contest until the problem was solved, and
twenty penalty points for each judged run. No penalty points are assessed for problems not solved.
Standings are based on most problems solved, with ties being broken by fewest penalty points.

The Problem:
Write a programming contest scoreboard.

The Input:
The first line has two integers. The first is the number of teams, and the second is the number of problems.
On the next line is the data for team 1. The first two numbers are the number of minutes and
number of judged runs for the first problem. If the problem was not solved then the number of minutes
is given as zero. The next two numbers are the number of minutes and number of judged runs for the
second problem, etc. The data for the team 2 follow on the next line, and so on.

The Output:
Print the headings:

PLACE TEAM NUMBER CORRECT PENALTY POINTS
Then, print the appropriate information for each team, in order of finish. Line up the numbers under the
appropriate heading so that the last digit of each number is alligned.

Use STDIN and STDOUT for the input and output. The test input file will be a .txt extenstion.

problemSet 1987.pdf -Adobe Acrobat Reader DC File Ecit View Window Help Home Tools problemSet1987.pdf x ? Sign In +) 100% Sample Input: 60 2 120 1 0 3 60 5 0 2 180 1 60 3 120 3 180 3 00 0 0 9 Sample Output: PLACE TEAM NUMBER CORRECT PENALTY POINTS 540 240 360 0 4 4 6:49 PM Type here to search 4/14/2018

Explanation / Answer

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Iterator;

public class contestscoreboard_10258 {

public static void main(String[] args) throws IOException {

// TODO Auto-generated method stub

InputStreamReader isr = new InputStreamReader(System.in);

BufferedReader br = new BufferedReader(isr);

int cases = Integer.parseInt(br.readLine());

int count = 0;

br.readLine();

HashMap<Integer,contestant> contestants = new HashMap<Integer,contestant>();

StringBuffer sb = new StringBuffer();

while(count<cases)

{

// Read blank line after each case

String line = br.readLine();

String [] params;

while(!line.trim().equals(""))

{

params = line.split(" ");

int contestant = Integer.parseInt(params[0]);

int problem = Integer.parseInt(params[1]);

int time = Integer.parseInt(params[2]);

char result = params[3].charAt(0);

contestant c;

if(contestants.containsKey(contestant))

{

c = contestants.get(contestant);

}

else

{

c = new contestant();

contestants.put(contestant, c);

}

if(!c.problems.contains(problem))

{

// if its correct

if(result == 'C')

{

c.penalty = c.penalty + time;

c.problems.add(problem);

c.solved++;

}

else if(result == 'I')

{

c.penalty = c.penalty+20;

}

}

line = br.readLine();

params = line.split(" ");

}

while(!contestants.isEmpty())

{

int max = getMaxKey(contestants);

contestant c = contestants.get(max);

sb.append(max+" "+c.solved+" "+c.penalty+" ");

contestants.remove(max);

}

sb.append(" ");

count++;

}

System.out.print(sb.toString());

}

public static int getMaxKey(HashMap<Integer,contestant> contestants)

{

Iterator<Integer> keys = contestants.keySet().iterator();

int max_solved = -1;

int max_time = -1;

int max_id = -1;

while(keys.hasNext())

{

int key = keys.next();

contestant c = contestants.get(key);

if(c.solved>max_solved)

{

max_id = key;

max_solved = c.solved;

max_time = c.penalty;

}

else if(c.solved== max_solved)

{

if(c.penalty>max_time)

{

max_id = key;

max_solved = c.solved;

max_time = c.penalty;

}

else if(c.penalty==max_time)

{

if(key<max_id)

{

max_id = key;

max_solved = c.solved;

max_time = c.penalty;

}

}

}

}

return max_id;   

}

}

class contestant

{

int solved;

ArrayList<Integer> problems;

int penalty;

public contestant()

{

solved = 0;

problems = new ArrayList<Integer> ();

penalty = 0;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote