-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcpp-maps.cpp
More file actions
33 lines (27 loc) · 835 Bytes
/
cpp-maps.cpp
File metadata and controls
33 lines (27 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Maps-STL
// Learn to use map container. Given some queries, add the marks to a corresponding student, delete a student and print the marks of a particular student.
//
// https://www.hackerrank.com/challenges/cpp-maps/problem
//
#include <string>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n;
map<string, int> students;
string name;
int mark;
int cmd;
cin >> n;
while (n-- != 0)
{
cin >> cmd;
if (cmd == 1) { cin >> name >> mark; students[name] += mark; }
else if (cmd == 2) { cin >> name; students.erase(name); }
else if (cmd == 3) { cin >> name; cout << students[name] << endl; }
}
return 0;
}