Deadline: 28 July 2004 at 19:00 GMT
Professor Dante, a horitculturist at Southern Shamest State School (SSSS), needs help assigning grades for the concluding semester. He has been recording assignments for the students in a text file all semester, and he needs a program to add up the scores, determine grades, and print the results alphabetically so he can easily copy the results into his gradebook.
School policy at SSSS demands that he assign grades according to the "flat-line-curve", which states that an equal number of students will receive A's, B's, C's, D's, and E's. If the number of students in the class doesn't divide evenly into the five grades, then up to one extra grade of each letter is given out, starting with A.
For example, if there were ten students in Dr. Dante's class, each letter grade would be assigned to two students, starting with the two top students receiving A's. However, if there were 12 students in the class, the top three students would receive A's, the next three B's, the next two C's, the next two D's, and the last two E's.
The input will be on stdin as a list of assignment scores. Each line contains the name of the student (which may contain spaces!), followed by a tab, and then followed by an integer score.
Output to stdout the grades for each student, one student per line, in alphabetical order and in the following format:
(name) scored (total_points) points and was given a grade of (letter_grade).
Where (name) is the student name, (total_points) is the sum of the scores for that student's assignments, and (letter_grade) is the final grade given the student.
Optimize for: code brevity
Brevity is defined as the total number of tokens in your source file. This means you are free (and encouraged) to use whitespace, sensible variable names, and comments -- they won't count against you.
jgbauman has created a utility for counting tokens. Download the source here or a prebuilt .exe here.
Given the input: (download the file, with tabs preserved, here)
- Code: Select all
Kybo Ren 72
Dave Sinkula 55
t i l e x 100
Colin Jeanne 99
Colin Jeanne 34
Kybo Ren 89
t i l e x 44
Dave Sinkula 94
Output should look like:
- Code: Select all
Alvaro scored 167 points and was given a grade of A.
Colin Jeanne scored 133 points and was given a grade of C.
Darobat scored 130 points and was given a grade of C.
Dave Sinkula scored 149 points and was given a grade of B.
Kybo Ren scored 161 points and was given a grade of B.
Lovechild scored 100 points and was given a grade of D.
Progler scored 85 points and was given a grade of E.
Ryan scored 88 points and was given a grade of D.
Vlad scored 167 points and was given a grade of A.
Zen scored 78 points and was given a grade of E.
loobian scored 100 points and was given a grade of D.
schloob scored 158 points and was given a grade of B.
t i l e x scored 144 points and was given a grade of C.
tougo scored 174 points and was given a grade of A.
- NO MACROS.
- You are to submit the source for a complete, working, compilable program -- not just a function this time!
- "Alphabetical order" is case-sensitive for this contest.
- Input will be valid. No input line will be longer than 256 characters.
- There will be more than 4 and less than 100 students in Dr. Dante's class.
- Score amounts will be no greater than 1000 and no less than -1000.
- There is no limit on the number of assignments.
Please attach your solution as a single .cpp file in an email to firstname.lastname@example.org, with the subject line as "Contest 39".
Post any questions or comments in this thread. Good luck and enjoy!