Advertisement
Guest User

Untitled

a guest
Aug 20th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. import java.util.*;
  2. import java.util.stream.Collectors;
  3.  
  4. public class SearchANumber {
  5.     public static void main(String[] args) {
  6.         Scanner in = new Scanner(System.in);
  7.  
  8.         List<Integer> numList = new ArrayList<>();
  9.  
  10.  
  11.         int[] inputNumbers = Arrays.stream(in.nextLine().split("\\s+"))
  12.                 .mapToInt(Integer::parseInt).toArray();
  13.  
  14.         int[] inputs = Arrays.stream(in.nextLine().split("\\s+")).mapToInt(Integer::parseInt).toArray();
  15.  
  16.         int numberElementsToTake = inputs[0];
  17.         int numberElementsToDelete = inputs[1];
  18.         int numberElementsToSearch = inputs[2];
  19.  
  20.  
  21.         for (int i = 0; i < numberElementsToTake; i++) {
  22.             numList.add(inputNumbers[i]);
  23.         }
  24.  
  25.  
  26.         for (int i = 0; i < numberElementsToDelete; i++) {
  27.             if(numList.size()>0){
  28.                 numList.remove(0);
  29.             }
  30.         }
  31.  
  32.  
  33.         if(numList.contains(numberElementsToSearch)){
  34.             System.out.println("YES!");
  35.         }else {
  36.             System.out.println("NO!");
  37.         }
  38.  
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement