Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayDeque;
- import java.util.Scanner;
- public class stack1_Exercises_Poisonous_Plants {
- public static void main(String[] args) throws IOException {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- ArrayDeque<Integer> plants = new ArrayDeque<>();
- for (int i = 0; i < n; i++) {
- plants.push(scanner.nextInt());
- }
- int days = 0;
- while (true) {
- int length = plants.size() - 1;
- for (int i = 0; i < length; i++) {
- int min = 0;
- min = plants.pop();
- if (min < plants.peek()) {
- plants.addLast(min);
- }
- }
- if (plants.size() != length + 1) {
- days++;
- } else {
- int result = days - 1;
- if (result < 0) {
- result = 0;
- } else if (result == 0) {
- result = 1;
- }
- System.out.println(result);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement