StefiIOE

[ADS] Card Trick

Nov 19th, 2020
426
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.LinkedList;
  5. import java.util.Queue;
  6. import java.util.Stack;
  7.  
  8.  
  9. public class card_trick {
  10.     public static int count(int N){
  11.  
  12.         int count = 0;
  13.         Stack<Integer> hand = new Stack<>();
  14.         Queue <Integer> deck = new LinkedList<>();
  15.         for(int i = 1 ; i < 52 ; i++){
  16.             deck.add(i);
  17.         }
  18.         while(deck.peek() != N){
  19.             for(int i = 0; i < 7 ; i++){
  20.                 hand.push(deck.poll());
  21.  
  22.             }
  23.             for(int i = 0 ; i < 7 ; i ++){
  24.                 Integer fromHand = hand.pop();
  25.                 Integer fromDeck = deck.poll();
  26.                 deck.add(fromHand);
  27.                 deck.add(fromDeck);
  28.             }
  29.             count++;
  30.         }
  31.         return count;
  32.     }
  33.  
  34.     public static void main(String[] args) throws NumberFormatException, IOException {
  35.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );
  36.         System.out.println(count(Integer.parseInt(br.readLine())));
  37.     }
  38.  
  39. }
  40.  
RAW Paste Data