6ta vezbanje

gorazd avatar
gorazd
java
02/02/2026 3:09 PM
1.3 KB
10
Indexable
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 counter = 0;
        Queue<Integer> queue = new LinkedList<>();
        Stack<Integer> stack = new Stack<>();
        for (int i = 1; i <= 51; i++) {queue.add(i);}

        while(queue.peek()!=N){
            counter++;
            for(int i = 0; i<7; i++){
                stack.push(queue.remove());
            }
            while(!stack.isEmpty()){
                queue.add(stack.pop());
                queue.add(queue.remove());
            }
        }
        return counter;
    }

	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())));
	}

}
Editor is loading...
Leave a Comment