-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-digits.cs
37 lines (32 loc) · 978 Bytes
/
find-digits.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Solution {
class Solution {
public static void Main(String[] args) {
int t = Convert.ToInt32(Console.ReadLine());
for(int a0 = 0; a0 < t; a0++){
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(Solution.GetDiviserCount( n, Solution.GetDigits(n) ));
}
}
static int[] GetDigits(int number)
{
List<int> digits = new List<int>();
while(number > 0)
{
digits.Add(number % 10);
number /= 10;
}
return digits.Where(x => x > 0).ToArray();
}
static int GetDiviserCount(int number, int[] digits)
{
int count = 0;
foreach(int x in digits)
count += number % x == 0 ? 1 : 0;
return count;
}
}
}