-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFind Digits.php
More file actions
49 lines (37 loc) · 784 Bytes
/
Find Digits.php
File metadata and controls
49 lines (37 loc) · 784 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
<?php
/**
* @author: syed ashraf ullah
* date: 21/04/2020
*/
// Complete the findDigits function below.
function findDigits($n) {
// Convert degit to char array
$arr = str_split($n);
$i = 0;
$size = sizeof($arr);
$count = 0;
while ($i < $size) {
if ($arr[$i] != 0 && $n % $arr[$i] == 0) {
$count++;
}
$i++;
}
return $count;
}
/**
* Sample #1
*/
// $n = 1012;
// $result = findDigits($n);
// echo $result;
// return;
$fptr = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");
fscanf($stdin, "%d\n", $t);
for ($t_itr = 0; $t_itr < $t; $t_itr++) {
fscanf($stdin, "%d\n", $n);
$result = findDigits($n);
fwrite($fptr, $result . "\n");
}
fclose($stdin);
fclose($fptr);