-
Notifications
You must be signed in to change notification settings - Fork 6
/
pair of complete strings.cpp
57 lines (49 loc) · 1.06 KB
/
pair of complete strings.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
#include <bits/stdc++.h>
using namespace std;
int count_complete(string x[],string y[],int len1,int len2){
int *bits_x=new int[len1];
int *bits_y=new int[len2];
for(int i=0;i<len1;++i)
{
int len= (x[i]).length();
for(int j=0; j<len; ++j)
{
int temp= x[i].at(j)-'a';
bits_x[i]= bits_x[i] | (1<<temp);
}
}
for(int i=0;i<len2;++i)
{
int len= y[i].length();
for(int j=0; j<len; ++j)
{
int temp= y[i].at(j)-'a';
bits_y[i]= bits_y[i] | (1<<temp);
}
}
int complete=1,z=25;
while(z--)
complete=(complete<<1)+1;
int count=0;
for(int i=0;i<len1;++i)
{
for(int j=0;j<len2;++j)
{
if((bits_x[i] | bits_y[j]) == complete)
count++;
}
}
return count;
}
int main() {
// your code goes here
string s1[]={"abcdefgh", "geeksforgeeks",
"lmnopqrst", "abc"};
string s2[]={"ijklmnopqrstuvwxyz",
"abcdefghijklmnopqrstuvwxyz",
"defghijklmnopqrstuvwxyz"};
int m= sizeof(s1)/sizeof(s1[0]);
int n= sizeof(s2)/sizeof(s2[0]);
cout<<count_complete(s1,s2,m,n);
return 0;
}