-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlucky numbers.cpp
More file actions
33 lines (32 loc) · 695 Bytes
/
lucky numbers.cpp
File metadata and controls
33 lines (32 loc) · 695 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
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
string s;
cin >> s;
int n=s.length(),flag=0;
map<long long,int> m;
for(int i=0;i<n;i++){
long long num=s[i]-'0';
m[num]+=1;
if(m[num]>1){
flag=1;
break;
}
for(int j=i+1;j<n;j++){
num*=(s[j]-'0');
m[num]+=1;
if(m[num]>1){
flag=1;
break;
}
}
}
if(flag==1) cout << "0\n";
else cout << "1\n";
}
return 0;
}
https://practice.geeksforgeeks.org/problems/lucky-number/0