To solve this problem you have to complete the code that you will find at the end of the statement. You have to replace each ??? with one or more lines of code. Do not change anything else. Download from the website of the problem the file code.cc with the code to be completed (click on the corresponding button “.CPP”), edit it and submit it to the judge.
A historian maintains a database with several anniversaries. For each one, we have the date, a brief description, and a number that indicates its relevance. Dates only include the month and the day (in this order), but not the year. In addition, the system only allows us to save one event for each date.
The historian’s program allows us to do five different operations:
n: It prints the number of stored anniversaries
preceded by “number events:”.
s
:
It stores that on date
the event
occurred, with relevance
.
It prints an error message if an event for date
has already been saved.
a
:
We ask the data of the anniversary of date
.
It is guaranteed that an event is stored for that date.
m: It prints the maximum relevance of the events
saved so far, preceded by “maximum relevance:”. If there
are no anniversaries yet, it prints 0.
e: It prints the sum of the relevances of the events
of the first date and of the last date (in chronological order; a direct
string comparison works fine). It prints an error message if there are
less than two events stored.
Input consists of several operations as indicated above. Dates use
two digits for the month and for the day, and a ‘/’ to
separate them. Descriptions are strings made with lowercase letters,
digits and dashes. Relevances are integer numbers between 1 and
.
For each operation (except save operations), print the requested information.
#include <iostream>
#include <map>
using namespace std;
struct Data {
string event;
int relevance;
};
int main() {
int maximum_relevance = 0;
map<string, Data> M;
char c;
while (cin >> c) {
if (c == 'n') {
???
}
else if (c == 's') {
string date, event;
int relevance;
cin >> date >> event >> relevance;
???
}
else if (c == 'a') {
string date;
cin >> date;
???
}
else if (c == 'm') {
???
}
else { // c == 'e'
???
}
}
}
Input
n m s 05/20 barca-champions-league 200 a 05/20 e s 11/20 franco-death 700 m s 09/11 fall-of-barcelona 1000 e m s 09/11 september-11-attacks 1001 n m a 09/11
Output
number events: 0 maximum relevance: 0 barca-champions-league ERROR: at least two events needed maximum relevance: 700 900 maximum relevance: 1000 ERROR: repeated date number events: 3 maximum relevance: 1000 fall-of-barcelona