Advertisement
SIRAKOV4444

Untitled

May 21st, 2020
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. import java.util.ArrayDeque;
  2. import java.util.Collections;
  3. import java.util.Scanner;
  4.  
  5. public class InspirationLab {
  6. public static void main(String[] args) {
  7. Scanner sc = new Scanner(System.in);
  8.  
  9. ArrayDeque<Integer> queue = new ArrayDeque<>();
  10.  
  11. String[] commands = sc.nextLine().split("\\s+");
  12. String[] nums = sc.nextLine().split("\\s+");
  13.  
  14. int N = Integer.parseInt(commands[0]);//add
  15. int S = Integer.parseInt(commands[1]);//remove/poll
  16. int X = Integer.parseInt(commands[2]);//true X or smallest
  17.  
  18. for (int i = 0; i < N; i++) {
  19. int toAdd = Integer.parseInt(nums[i]);
  20. queue.add(toAdd);
  21. }
  22. for (int i = 0; i < S; i++) {
  23. if(!queue.isEmpty()) {
  24. queue.remove();
  25. }
  26. }
  27. if (queue.contains(X)) {
  28. System.out.println("true");
  29. } else {
  30. if (!queue.isEmpty()) {
  31. int start = queue.peek();
  32. for (int i = 0; i < queue.size(); i++) {
  33. int currentNum = queue.peek();
  34. if (currentNum < start) {
  35. start = currentNum;
  36. }
  37. }
  38. System.out.println(start);
  39. } else {
  40. System.out.println(0);
  41. }
  42. }
  43.  
  44.  
  45. }
  46. }
  47. //4 1 666
  48. //666 69 13 420
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement