(30 points--CS140Sp18-Mid2-Contest): Write a C++
program to score af contest.
Standard input is composed of lines of text, where each line contains a person's first name and the name of a problem they have correctly solved. A person gets credit
for solving the problem only if they are the first person to have solved the
problem. The winner is the person or persons who correctly solves the most problems.
Your job is to write a program that prints out the name of the winning
person(s) and the number of problems they were credited with solving. Put
a single space between the winner's name and the number of problems
they solved. If there is a tie, then print the names of all of the winning
persons in alphabetical order with each person printed on a new line. The only data structures you are allowed to use are sets and
maps from the C++ Standard Template library. While your solution will
have to keep track of which problems have been previously solved, it
does not have to keep track of which person solved the problem since
the problem description does not ask you to print the problems that the
winner(s) solved.
Here are two examples. If the sample input is:
Kyle SRM-394
Banajee SRM-405
Sue SRM-591
Nancy P-486
Joe SRM-394
Sue SRM-394
Lee B-4839
Sue P-486
Lee SRM-394
Lee SRM-405
Sue P-383
Then your program would print:
Sue 2
since Sue was the first person to solve problems SRM-591 and P-383. Notice
that Sue does not get credit for either SRM-394 or P-486 because someone
solved those problems before her.
If the input included the additional line:
Lee SRM-001
then your program would print:
Lee 2
Sue 2
Constraints:
- The input is guaranteed to contain at least one line and is error
free.
- You must use STL maps and sets to solve this problem.
- You cannot assume that every problem will include a number. The type
of a problem is a string, not an integer.
Handy Methods From The STL's Set API
- .begin(): Returns an iterator to the first element in the set
- .end(): Returns an iterator to the set's sentinel node
- .insert(value): Adds a new value to the set and returns
a pair <set<string>::iterator, bool> element.
The iterator points to the inserted value, if the insert succeeded,
and the bool indicates whether or not the insert succeeded. The
insert succeeds if the value was not previously in the set and fails
otherwise.
- .find(key): Returns an iterator to the set element that
matches key if key is found in the set. If the key is not in the
set, then find returns an iterator that points to the
set's sentinel node.
Handy Methods From The STL's Map API
- .begin(): Returns an iterator to the first element in the map
- .end(): Returns an iterator to the map's sentinel node
- .find(key): Returns an iterator that points to the node containing
the key/value pair if the key is found in the map and that points to
the map's sentinel node if the key is not found. The specific return
value is a pointer to a
pair<key_type first, value_type second> object.
- .insert(make_pair(key, value)): Adds a new key/value pair to the
map.
- Map_Name[key]: treats the map as an associative map and returns
the value associated with the key if Map_Name[key] is on the right hand side of
the assignment statement and assigns a value to the key if Map_Name[key]
is on the left hand side of the assignment statement.