-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathE0062.cpp
More file actions
37 lines (33 loc) · 693 Bytes
/
E0062.cpp
File metadata and controls
37 lines (33 loc) · 693 Bytes
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
/*
Problem Statement: https://www.hackerrank.com/challenges/gem-stones/problem
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int gemstones(vector<string> arr) {
string curr, last;
for(size_t i=0 ; i<arr.size() ; i++)
sort(arr[i].begin(), arr[i].end());
last = arr[0];
for(size_t i=1 ; i<arr.size() ; i++){
set_intersection(last.begin(), last.end(), arr[i].begin(), arr[i].end(), back_inserter(curr));
swap(last, curr);
curr.clear();
}
return last.size();
}
int main()
{
int n;
string s;
vector<string> arr;
cin>>n;
cin.ignore();
for(int i=0 ; i<n ; i++){
getline(cin, s);
arr.push_back(s);
}
cout<<gemstones(arr);
return 0;
}