Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. public class DroppingNumbers
  2. {
  3.     public static void main(String[] args)
  4.     {
  5. loop:
  6.         for (long i=12; i<=987654321L; i++)
  7.         {
  8.             String s=""+i;
  9.  
  10.             int[] count=new int[10];
  11.             for (int k=0; k<s.length(); k++)
  12.             {
  13.                 int d=(int)(s.charAt(k)-'0');       //dropped digit
  14.                 if (d==0) continue loop;        //cannot have digit 0
  15.  
  16.                 count[d]++;
  17.                 if (count[d]==2) continue loop;     //cannot have repeated digits
  18.  
  19.                 String s2=s.substring(0,k)+s.substring(k+1);
  20.                 if (Long.parseLong(s2)%d!=0) continue loop;         //truncated number does not divide by d
  21.             }
  22.  
  23.             System.out.println(s);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement