Advertisement
SensaBG

petazadacha

Aug 28th, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int[] numbers = Arrays
  9.                 .stream(scanner.nextLine().split(" "))
  10.                 .mapToInt(Integer::parseInt)
  11.                 .toArray();
  12.  
  13.         int biggestNum = 0;
  14.         int foundAtIndex = -1;
  15.  
  16.         for (int i = 1; i < numbers.length; i++) {
  17.             int currentNum = numbers[i];
  18.             if (currentNum > biggestNum) {
  19.                 biggestNum = currentNum;
  20.                 foundAtIndex = i;
  21.             }
  22.         }
  23.  
  24.         for (int i = foundAtIndex; i < numbers.length - 1; i++) {
  25.             int currentNum = numbers[i];
  26.             boolean isBigger = false;
  27.  
  28.             for (int j = i + 1; j <= numbers.length - 1; j++) {
  29.                 int compareNum = numbers[j];
  30.                 if (currentNum <= compareNum) {
  31.                     isBigger = true;
  32.                     break;
  33.                 }
  34.             }
  35.  
  36.             if (!isBigger) {
  37.                 System.out.print(currentNum + " ");
  38.             }
  39.         }
  40.         System.out.println(numbers[numbers.length - 1]);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement