forked from amankayat/HackerRank-Solution-Algorithm-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_digit.cpp
More file actions
53 lines (42 loc) · 681 Bytes
/
find_digit.cpp
File metadata and controls
53 lines (42 loc) · 681 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
#include<iostream>
#include<stdio.h>
using namespace std;
int find_digit(int n){
int count=0,len;
int copy_n = n;
int copy_n_2= n;
//find integer length
if(n>0){
for(len=0;n>0;len++){
n = n/10;
}
}
//store integer one by one into array
int store[len];
for(int i=len-1;i>=0;i--){
store[i] = copy_n%10;
copy_n/=10;
}
//main operation
for(int i=0;i<len;i++){
if(store[i]>0){
if(copy_n_2%store[i]==0){
count++;
}
}else{
}
}
return count;
}
int main(){
int test,k=0;
int n,results[15];
cin>>test;
for(int i=0;i<test;i++){
cin>>n;
results[k] = find_digit(n);
k++;
}
for(int j=0;j<k;j++)
cout<<results[j]<<"\n";
}