Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

HackerRank Maps-STL solution in C++ programming

YASH PAL, 31 July 202416 January 2026

HackerRank Maps-STL C++ Solution – In this HackerRank Maps-STL problem in the C++ programming language, you are appointed as the assistant to a teacher in a school, and she is correcting the answer sheets of the students. Each student can have multiple answer sheets. So the teacher has Q queries:

  1. X Y: Add the mark Y to the student whose name is X.
  2. X: Erase the marks of the students whose name is X.
  3. X: Print the marks of the students whose name is X. (If X didn’t get any marks, print 0.)
HackerRank Maps-STL solution in c++ programming

HackerRank Maps-STL problem solution in C++ programming.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  
    int q,type;
    cin>>q;
    string name;
    int marks;

    map<string,int> m;
    for(int i=0;i<q;i++)
    {
     cin>>type;
    switch(type) {
    
    case 1:
    cin>>name>>marks;

    if(m.find(name)==m.end())
    m.insert(make_pair(name,marks));
else
m[name]+=marks;

break;

case 2:
cin>>name;
m.erase(name);
break;

case 3:
cin>>name;
m.find(name)!=m.end()?cout<<m.find(name)->second<<endl:cout<<"0"<<endl;
break;

}

} 
return 0;
}

Second solution

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
using namespace std;


int main() {
    int n;
    cin >> n;
    
    map<string, int> m;
    
    while (n--) {
        int t;
        cin >> t;
        
        string s;
        cin >> s;
        
        if (t == 1) {
            int a;
            cin >> a;
            
            m[s] += a;
        } else if (t == 2) {
            m[s] = 0;
        } else {
            cout << m[s] << "n";
        }
    }
    
    return 0;
}

C++ Solutions coding problems solutions Hackerrank Problems Solutions cppHackerRank

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

HackerRank C++ Problems Solutions
Say “Hello, World!” with C++ solution
Input and Output solution
Basic Data Types solution
Conditional Statements solution
For loop solution
Functions solution
Pointer solution
Arrays Introduction solution
Variable-Sized Arrays solution
Attribute Parser solution
StringStream solution
Strings solution
Structs solution
Class solution
classes and objects solution
Box It! solution
Inherited code solution
Exceptional server solution
Virtual Functions solution
Abstract Classes — Polymorphism solution
Vector-Sort solution
Vector-Erase solution
Lower Bound-STL solution
Sets-STL solution
Maps-STL solution
Print Pretty solution
Deque-STL solution
Inheritance Introduction solution
Hotel Prices solution
Cpp exception handling solution
Rectangle Area solution
Multi-Level Inheritance solution
Overloading Ostream Operator solution
Messages Order solution
Accessing Inherited Functions solution
Magic Spells solution
C++ Class Templates problem solution
Preprocessor Solution
Operator Overloading solution
Overload Operators solution
Attending workshops solution
C++ Class Template Specialization solution
C++ Variadics problem solution
Bit Array solution

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes