Monday, 4 April 2016

hackerrank:Find Digits

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution
{
public static void main(String[] args)
{
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc=new Scanner(System.in);
int test=sc.nextInt();
while(test>0)
{
int count=0;  
int n=sc.nextInt();
int arr[]=new int[12];
int i=0;
int temp=n;
while(n>0)
{
arr[i]=n%10;
n=n/10;
i++;
}
n=temp;
for(int k=0;k<i;k++)
{
if(arr[k]!=0)
{
if(n%arr[k]==0)
count++;
}
}
System.out.println(count);
test--;
}
}
}        

No comments:

Post a Comment