-
Notifications
You must be signed in to change notification settings - Fork 8
/
vectoruse.cpp
71 lines (68 loc) · 1.21 KB
/
vectoruse.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <bits/stdc++.h>
using namespace std;
int gemstones(vector <string> arr)
{
int l = arr.size();
int i,j,k,flag=1;
//cout << arr[0][1]<<endl;/*
string str;
//cin >> str;
//arr.push_back(str);
//l = arr.size();
//cout << arr[3]<<endl;
int gem[l][26];
int final=0;
for (i = 0; i < l; i++)
{
for(j = 0;j<26;j++)
{
gem[i][j] = 0;
}
}
for(i=0;i<l;i++)
{
str = arr[i];
int count = arr[i].length();
int ch;
for (j=0;j < count; j++)
{
ch = str[j] - 'a';
gem[i][ch] = gem[i][ch]+1;
ch = 0;
}
}
for (i = 0; i < 26; i++)
{
int key = gem[0][i];
for (j = 1; j < l; j++)
{
if(gem[j][i]!=key)
{
if(gem[j][i] == 0)
flag = 0;
else
{
if(key>gem[j][i])
key = gem[j][i];
}
}
}
if(flag == 1)
final = final + key;
else
flag = 1;
}
//cout <<l <<endl;
return final;
}
int main() {
int n;
cin >> n;
vector<string> arr(n);
for(int arr_i = 0; arr_i < n; arr_i++){
cin >> arr[arr_i];
}
int result = gemstones(arr);
cout << result << endl;
return 0;
}