Advertisement
dimipan80

Exam 1. Stuck Numbers

Sep 15th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _1_StuckNumbers {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         Scanner scan = new Scanner(System.in);
  8.         int count = scan.nextInt();
  9.  
  10.         int[] numbers = new int[count];
  11.         for (int i = 0; i < numbers.length; i++) {
  12.             numbers[i] = scan.nextInt();
  13.         }
  14.  
  15.         boolean isFoundStuckNumbers = false;
  16.         String leftStr, rightStr;
  17.         for (int a : numbers) {
  18.             for (int b : numbers) {
  19.                 if (b != a) {
  20.                     for (int c : numbers) {
  21.                         if (c != a && c != b) {
  22.                             for (int d : numbers) {
  23.                                 if (d != a && d != b && d != c) {
  24.                                     leftStr = "" + a + b;
  25.                                     rightStr = "" + c + d;
  26.                                     if (leftStr.equals(rightStr)) {
  27.                                         isFoundStuckNumbers = true;
  28.                                         System.out.printf("%d|%d==%d|%d%n", a, b, c, d);
  29.                                     }
  30.                                 }
  31.                             }
  32.                         }
  33.                     }
  34.                 }
  35.             }
  36.         }
  37.  
  38.         if (!isFoundStuckNumbers) {
  39.             System.out.println("No");
  40.         }
  41.     }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement