-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwinning-lottery-ticket.cpp
More file actions
55 lines (47 loc) · 922 Bytes
/
winning-lottery-ticket.cpp
File metadata and controls
55 lines (47 loc) · 922 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
using namespace std;
int frq[1030];
int main() {
// your code goes here
int n,i=0,j=0,max=0;
string id;
cin>> n;
for(i=0;i<1030;i++)
frq[i]=0;
for( j =0; j<10;j++)
{
max |= 1<<j;
//cout<<"max = "<<max<<endl;
}
for(i=0;i<n;i++)
{
int b=0,r=0;
cin>>id;
for(j=0;j<id.length();j++)
{
r=id[j]-48;
b= b|(1<<r); //this is the code of the string
}
frq[b]++;//cout<< b;
}
//for(i=0;i<1030;i++) if(frq[i]>0) {cout<<i<<": "<< frq[i]<<"\n";}
int count=0;
for(i=0;i<1030;i++)
{
if(frq[i]>0)
{
for(j=i+1;j<1030;j++)
{
if(frq[j]>0)
{
if((i|j) == max)
count=count+frq[i]*frq[j];
}
}
if(i==max)
count+=((frq[i]*(frq[i]-1))/2);
}
}
cout<< count<<"\n";
return 0;
}