Creating the ultimate apple pie requires effort.
There are N apple pies (numbered 0, 1, ..., N-1) that need to undergo quality control testing. Each apple pie will be tasted and scored by K individuals.
To eliminate outliers, each apple pie will have its highest and lowest scores removed from the K scores it receives, leaving only the remaining K-2 scores.
Only when the average of these K-2 scores is greater than or equal to the T value do we consider it a passing apple pie.
Please assist in writing a program to complete the quality control testing for apple pies.
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
The first line contains three positive integers N, K, and T (where 3 ≤ N, K, T ≤ 1000). This signifies that there are N apple pies in total, and each apple pie will be evaluated by K individuals. Also, the average score after removing the highest and lowest scores must be greater than or equal to the passing threshold T. Next, there are N lines, each with K positive integers xi (where 1 ≤ xi ≤ 1000). This signifies the scores given to the apple pie, with no repetitions in the scores for the same apple pie. For the same apple pie, all xi ≠ xj. | For apple pies that pass the quality control test, print their IDs in ascending order (starting ID is 0), with a line break between each pair. If there are no passed apple pies, print "A is for apple." |
7 4 40 1 2 4 8 8 5 2 3 3 4 1 8 7 6 1 5 1 8 4 7 3 2 8 6 1 3 2 7 | A is for apple. |
9 7 10 9 15 13 2 6 3 12 12 14 4 5 3 7 19 10 8 4 14 6 18 19 11 17 1 19 4 6 3 8 13 14 16 12 3 17 4 9 8 3 19 17 7 19 2 12 4 1 15 8 11 16 4 12 1 5 19 1 11 9 6 4 19 15 | 2 4 |
Thought Process
While collecting data, determine the maximum and minimum values simultaneously and calculate the sum of all scores. Then, subtract the maximum and minimum values from the sum and calculate the average. You can use float/double data types to calculate the average.
A Boolean variable ok can be initialized to false. If there are any passed apple pies, set ok to true. After all loops have finished, if ok is still false, print "A is for apple."
Sample Code-ZeroJudge G307: Apple Pie
#include <iostream>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int N, K, T;
cin >> N >> K >> T;
bool ok = false;
for (int i = 0; i<N; i++) {
int max = -999, min = 99999, sum = 0;
for (int j = 0; j<K; j++) {
int tmp;
cin >> tmp;
sum += tmp;
if (tmp > max) max = tmp;
if (tmp < min) min = tmp;
}
sum -= max;
sum -= min;
const double average = double(sum)/(K-2);
if (average >= T) {
cout << i << "\n";
ok = true;
}
}
if (!ok) cout << "A is for apple.\n";
}
//ZeroJudge G307
//Dr. SeanXD