Judging Olympiad

From Progteam

Revision as of 08:26, 21 September 2008 by MuGMaN (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Checkmark.jpg This problem has been solved by Eric.

Judging Olympiad
Problem Number 3507
Sorter: Eric
Source: Arab and North Africa 2007
Link: http://acm.pku.edu.cn/JudgeOnline/problem?id=3507

Judging Olympiad is problem number 3507 on the Peking University ACM site.


Problem Information

Problem Name: Judging Olympiad
Problem Number on PKU: 3507
Synopsis: A panel of 6 judges came up with an impartial way to judge a program on the ICPC contest. Of 6 scores from 6 judges, drop the highest and the lowest scores and calculate the average of the remaining 4 scores. Note: the result should be in double precision but should not contain any unnecessary decimals or leading zeros.

Solver Information

Solver: Eric Hong
Date: September 21, 2008


Yet another late sleepless night on a weekend. It was particularly hard to come up with the ways to end input and format the results.

General Strategy

  1. Using Scanner, take the input.
  2. Populate the scores into an ArrayList list.
  3. Sort list and drop the first and the last item.
  4. Find the average.

Ending Input

  1. Add all the elements.
    1. If the sum is 0, end input.
    2. Otherwise, keep taking inputs.

Formatting Output

  1. Parse the double average to int
    1. If two numbers are equal, print int
    2. Otherwise, print double


import java.util.*;

public class Main
	public static Scanner in;

	public static void main(String[] args)
		in = new Scanner(System.in);

	public static void doStuff()
		while (in.hasNextLine())
			ArrayList<Integer> list = new ArrayList<Integer>();
			int sum = 0;
			for (int i = 0; i < 6; i++)
				int num = in.nextInt();
				sum += num;
			if (sum  != 0)
				list.remove(list.size() - 1);

	public static void solve(ArrayList list)
		double sum = 0;
		for (int i = 0; i < 4; i++)
			sum = sum + (Integer) list.get(i);
		double avg = sum / 4;
		int num = (int) avg;
		if (avg == num)

Additional Remarks

Memory: 5460K
Time: 391MS

This solution may not be as efficient as it can be. Any smarter way to format the output better?

Personal tools