Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.math.*;
- class Solution {
- public static void main(String args[]) {
- Scanner in = new Scanner(System.in);
- int n = in.nextInt();
- int m = in.nextInt();
- //smallest
- String k = "";
- int i = 0;
- // n digits
- while(k.length() != n)
- {
- k = "";
- k+= i;
- i++;
- }
- i--;
- // k distincts digits
- while(allDistincts(k)!=true)
- {
- k = "";
- i++;
- k+=i;
- }
- // max nombre avec 3 digits
- String d = "";
- int x = 0;
- while(d.length() != n+1)
- {
- d = "";
- d += x;
- x++;
- }
- x-=2;
- String max = "";
- max += x;
- // k distincts digits
- while(allDistincts(max)!=true)
- {
- max = "";
- x--;
- max+=x;
- }
- System.out.print(k);
- System.out.print(" ");
- System.out.println(max);
- }
- public static boolean allDistincts(String s)
- {
- boolean retour = true;
- for(int i = 0; i < s.length(); i++)
- {
- char e = s.charAt(i);
- for(int j = 0; j < s.length(); j++)
- {
- if(j != i && e == s.charAt(j))
- retour = false;
- }
- }
- return retour;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement