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.LinkedList;
- import java.util.Queue;
- import java.util.Stack;
- public class card_trick {
- public static int count(int N){
- int count = 0;
- Stack<Integer> hand = new Stack<>();
- Queue<Integer> deck = new LinkedList<>();
- for (int i = 1; i < 52; i++) {
- deck.add(i);
- }
- while (deck.peek() != N){
- for (int i = 0; i < 7; i++) {
- hand.push(deck.poll());
- }
- for (int i = 0; i < 7; i++) {
- Integer fromHand = hand.pop();
- Integer fromDeck = deck.poll();
- deck.add(fromHand);
- deck.add(fromDeck);
- }
- count++;
- }
- return count;
- }
- public static void main(String[] args) throws NumberFormatException, IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );
- System.out.println(count(Integer.parseInt(br.readLine())));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement