Friday, January 1, 2021

Maps-STL | HackerRank | C++ | Solution | Color The Code



Problem : https://www.hackerrank.com/challenges/cpp-maps/problem

Solution : 

#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;
    cin>>Q;
    map<string,int>mp;
    while(Q--){
        int type;
        cin>>type;
        if(type == 1){
            string name;
            int marks;
            cin>>name>>marks;
            if(mp.find(name)!=mp.end()){
                mp[name] = mp[name] + marks;
            }else{
                mp[name] = marks;
            }
            
        }else if(type == 2){
            
            string name;
            cin>>name;
            mp[name] = 0;
        }else if(type == 3){
            string name;
            cin>>name;
            cout<<mp[name]<<endl;
        }
    }
    return 0;
  
}




No comments:

Post a Comment