분류 전체보기
-
1021) 회전하는 큐 c++백준코딩일기 2020. 11. 4. 20:57
문제 ) www.acmicpc.net/problem/1021 1021번: 회전하는 큐 첫째 줄에 큐의 크기 N과 뽑아내려고 하는 수의 개수 M이 주어진다. N은 50보다 작거나 같은 자연수이고, M은 N보다 작거나 같은 자연수이다. 둘째 줄에는 지민이가 뽑아내려고 하는 수의 위치가 www.acmicpc.net 풀이 ) 맨 처음 큐의 크기 N을 입력받으면 1~N 까지의 수를 가진 큐를 갖게 되고, M 번 뽑는다. 지민이가 뽑는 카드를 target 이라는 변수로 입력을 받고, target 이 맨앞에 있다면 바로 pop_front 를해서 없앴고, 맨 앞에 있지 않다면 왼쪽으로 회전할지, 오른쪽으로 회전할지 정해야한다. 회전을 정하는 방법은 덱을 처음부터 돌면서 target 이 현재 덱에서 몇 번 째에 있는지 ..