-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcount_elements_matching_rule.cpp
41 lines (39 loc) · 1.04 KB
/
count_elements_matching_rule.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
#include <bits/stdc++.h>
using namespace std;
int countMatches(vector<vector<string>>& items, string ruleKey, string ruleValue) {
int count =0;
for(int i=0; i<items.size(); i++){
if(ruleKey=="type")
if(items[i][0]==ruleValue)
count++;
if(ruleKey == "color")
if(items[i][1]==ruleValue)
count++;
if(ruleKey == "name")
if(items[i][2]==ruleValue)
count++;
}
return count;
}
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string ruleKey, ruleValue;
cin>>ruleKey>>ruleValue;
vector<vector<string>> items;
for(int i=0; i<n; i++){
vector<string> s;
for(int j=0; j<3; j++){
string temp;
cin>>temp;
s.push_back(temp);
}
items.push_back(s);
}
cout<<countMatches(items, ruleKey, ruleValue)<<endl;
}
return 0;
}