# Judging Olympiad

### From Progteam

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.

## Contents |

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

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

- Using Scanner, take the input.

- Populate the scores into an ArrayList list.

- Sort list and drop the first and the last item.

- Find the average.

*Ending Input*

- Add all the elements.

- If the sum is 0, end input.

- Otherwise, keep taking inputs.

- If the sum is 0, end input.

*Formatting Output*

- Parse the double average to int

- If two numbers are equal, print int

- Otherwise, print double

- If two numbers are equal, print int

## 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(); list.add(num); 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); } } }

## 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?