Advertisement
Guest User

Untitled

a guest
Jan 24th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.util.Arrays;
  6. import java.util.Stack;
  7.  
  8. public class Cokiskoki {
  9.  
  10.  
  11.     public static void main(String[] args) throws IOException {
  12.  
  13.  
  14.         testInput();
  15.         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  16.         in.readLine();
  17.         int max = 0;
  18.  
  19.  
  20.         int[] arr = Arrays.stream(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  21.         int out[] = new int[arr.length];
  22.  
  23.  
  24.         for (int i = arr.length - 2; i >= 0; i--) {
  25.             for (int j = i + 1; j < arr.length; j++) {
  26.                 if (arr[i] < arr[j]) {
  27.                     out[i] = out[j] + 1;
  28.                     max = Math.max(max, out[i]);
  29.                     break;
  30.                 }
  31.             }
  32.         }
  33.  
  34.  
  35.         StringBuilder result = new StringBuilder("");
  36.         for (int i = 0; i < out.length; i++) {
  37.             result.append(out[i]);
  38.             result.append(" ");
  39.         }
  40.  
  41.         System.out.println(max);
  42.         System.out.println(result.toString().trim());
  43.  
  44. //        System.out.println(result.reverse().toString().trim());
  45.  
  46.  
  47.  
  48.  
  49.  
  50.     }
  51.  
  52.     public static void testInput() {
  53.         String test = "5\n" +
  54.                 "1 1 1 1 1";
  55.         System.setIn(new ByteArrayInputStream(test.getBytes()));
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement