-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmap.cpp
55 lines (34 loc) · 967 Bytes
/
map.cpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Q Given two sets of strings of n and k,Count the number of occurences of each string 1<=i<=k in n.
E.g:-
Input
n={"TLE" ,"WAontestcase1", "AC" ,"RE" ,"WAontestcase1", "gohome"}
k={"WA","TLE","RE","AC"}
output
WA:0 TLE:1 RE:1 AC:1
How the map looks after insertion into the map
"WA","TLE","RE","AC" "WAontestcase1" "gohome"
| | | | | |
0 1 1 1 2 1
*/
#include<bits/stdc++.h>
using namespace std;
void countOccurence(vector<string> n,vector<string> k)
{
unordered_map<string,int> mp;
for(int i=0;i<n.size();i++)
{
mp[n[i]]++;
}
for(int i=0;i<k.size();i++)
{
cout<<k[i]<<":"<<mp[k[i]]<<" ";
}
}
int main()
{
vector<string> n = {"TLE" ,"WAontestcase1", "AC" ,"RE" ,"WAontestcase1", "gohome"};
vector<string> k={"WA","TLE","RE","AC"};
countOccurence(n,k);
return 0;
}