Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- import java.util.Stack;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Stack<Integer> st = new Stack<Integer>();
- int count = sc.nextInt();
- int countToPop = sc.nextInt();
- int numToCheck = sc.nextInt();
- int minNumber = Integer.MAX_VALUE;
- sc.nextLine();
- for (int i = 0; i < count; i++) {
- st.push(sc.nextInt());
- }
- if (st.isEmpty()){
- System.out.println(0);
- } else {
- for (int i = 0; i < countToPop; i++) {
- st.pop();
- }
- if (st.size() == 0){
- System.out.println(0);
- return;
- }
- if (st.contains(numToCheck)){
- System.out.println(true);
- } else {
- int size = st.size();
- for (int i = 0; i < size; i++) {
- if (minNumber > st.peek()){
- minNumber = st.pop();
- } else {
- st.pop();
- }
- }
- System.out.println(minNumber);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement