Advertisement
Guest User

Untitled

a guest
Jan 24th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. package second;
  2.  
  3. import java.util.Scanner;
  4. import java.util.Stack;
  5.  
  6. public class CokiSkoki {
  7. public static void main(String[] args) {
  8. Scanner sc = new Scanner(System.in);
  9. Stack<Integer> buildings = new Stack<>();
  10.  
  11. int n = sc.nextInt();
  12. for (int i = 0; i < n; i++) {
  13. buildings.push(sc.nextInt());
  14. }
  15.  
  16. Stack<Integer> jumpSize = new Stack<>();
  17. Stack<Integer> result = new Stack<>();
  18.  
  19. int max = 0;
  20. while (!buildings.isEmpty()) {
  21. if (jumpSize.isEmpty()) {
  22. jumpSize.push(buildings.pop());
  23. result.push(0);
  24. } else if (buildings.peek() < jumpSize.peek()) {
  25. jumpSize.push(buildings.pop());
  26. result.push(jumpSize.size() - 1);
  27. } else {
  28. jumpSize.pop();
  29. }
  30. if (max < result.peek()) {
  31. max = result.peek();
  32. }
  33. }
  34.  
  35. System.out.println(max);
  36. while (!result.isEmpty()) {
  37. System.out.print(result.pop() + " ");
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement