List of all available Websheets
Viewing cpp/exam_practice/FoodPart1 by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | Please see <a href="http://www.cs.princeton.edu/courses/archive/spr15/cos126/docs/mid1-s13-prog.pdf">the programming exam page</a>. <br> We recommend doing this practice in a timed environment; give yourself 90 minutes. |
Public permissions | |
Engine | |
Template / Reference solution | // NOTE: The actual exam will not use Websheets (instead, the PA submit system). // It's recommended to practice and test on your own machine and copy here to check. \[ /******************************************************************* Reference solution for Foodlympics Part One: Competitive Cuisine Description: Reads in judge rankings for C countries by J judges. Prints out the rounded average score for each country, excluding the min and max. **************************************************************************/
using namespace std; // excluding the min and max, compute the rounded average // of the entries of judgeRatings // J is the number of judges int score(int judgeRatings[], int J) { int sum = 0; int min = judgeRatings[0]; int max = judgeRatings[0]; for (int i = 0; i < J; i++) { if (judgeRatings[i] > max) max = judgeRatings[i]; if (judgeRatings[i] < min) min = judgeRatings[i]; sum += judgeRatings[i]; } // eliminate min and max sum = sum - min - max; // average double ave = sum / (double) (J - 2); // rounded average, excluding min and max int score = (int) round(ave); return score; } // read the judges' ratings for several countries // from standard input and print their overall scores // to standard output int main() { int C; // number of countries int J; // number of judges cin >> C >> J; // read the input cout << C << endl; // first line of output // for each country, process their ratings for (int i = 0; i < C; i++) { // read the next line of input string name; cin >> name; int ratings[100]; for (int j = 0; j < J; j++) cin >> ratings[j]; // compute the overall score int overall = score(ratings, J); // output for this country cout << name << " " << overall << endl; } } ]\ |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [ {"stdin": "6 3\nGER 1 13 20\nBEL 15 15 15\nAUT 17 18 3\nCHF 19 7 19\nLUX 14 14 15\nLIE 7 8 9"}, {"stdin": "3 6\nCanada 10 16 10 20 14 10\nMexico 14 14 14 14 14 14\nUSA 7 14 20 12 15 16"}, {"stdin": "1 3\nPangaea 8 8 8"}, {"stdin": "6 3\nLMH 1 2 3\nLHM 4 6 5\nMLH 8 7 9\nMHL 11 12 10\nHLM 15 13 14\nHML 18 17 16"}, {"stdin": "6 3\nLLH 1 1 9\nLHL 1 9 1\nHLL 9 1 1\nLHH 1 9 9\n HLH 9 1 9\nHHL 9 9 1"}, {"stdin": "2 3\noneLand 1 1 1\ntwentyStan 20 20 20"}, {"stdin": "4 4\nmaxRepeat 18 18 7 5\nminRepeat 6 6 12 19\nbothRepeat 4 4 12 12\nfours 4 4 4 4"} ] |
Solution visibility |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.