(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 This problem has been solved by Eric.

 Sorter: Eric Arab and North Africa 2007 http://acm.pku.edu.cn/JudgeOnline/problem?id=3507

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

## Problem Information

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

## Trivia

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. 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

## Solution

```import java.util.*;

public class Main
{
public static Scanner in;

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

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)
{
Collections.sort(list);
list.remove(0);
list.remove(list.size() - 1);
solve(list);
}
}
}

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)
{
System.out.println(num);
}
else
{
System.out.println(avg);
}
}
}
```