-
Notifications
You must be signed in to change notification settings - Fork 110
/
solution.cpp
41 lines (35 loc) · 887 Bytes
/
solution.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
/*
@Author : Harikrishnan6336
HackerRank question :- Sparse Arrays
https://www.hackerrank.com/challenges/sparse-arrays/problem
Prerequisite: Character Arrays
Solution intuition: A simple Linear search is the most efficient solution.
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
string strs[1001];
int q,m;
cin>>m; // m - number of strings
for(unsigned long int i=0;i<m;i++)
{
cin>>strs[i]; // Input the strings
}
cin>>q; // q - number of queries
for(unsigned long int i=0;i<q;i++)
{
int cnt=0; //count of the occurence of query string 's' in strs
string s;
cin>>s;
for(unsigned long int j=0;j<m;j++)
{
if(s == strs[j])
{
cnt++;
}
}
cout<<cnt<<"\n";
}
return 0;
}