입력 코드
#include <stdio.h>
int findMax(int queue[], int N, int front, int rear){
int M = queue[front], index = 0;
for (int i = front + 1; i <= rear; i++)
if (M < queue[i])
M = queue[i], index = i;
return index;
}
int main(){
int tc, N, M, queue[10000], maxIndex, front, rear, now;
scanf("%d", &tc);
while (tc--){
scanf("%d%d", &N, &M);
front = now = 0, rear = N - 1;
for (int i = 0; i < N; i++)
scanf("%d", &queue[i]);
while (front - 1 != M){
maxIndex = findMax(queue, N, front, rear);
for (int i = front; i < maxIndex; i++){
queue[++rear] = queue[front++];
M = M == front - 1 ? rear : M;
}
front++;
now++;
}
printf("%d\n", now);
}
return 0;
}
코드 설명
#구현 #자료구조 #시뮬레이션 #큐
References
[백준] 1966 프린터 큐
문제 링크 : https://www.acmicpc.net/problem/1966 1966번: 프린터 큐 문제 여러분도 알다시피 여러분의 프린터 기기는 여러분이 인쇄하고자 하는 문서를 인쇄 명령을 받은 ‘순서대로’, 즉 먼저 요청된 것
taesan94.tistory.com
blog.naver.com/knight7024/221195121158
[백준] 1966번: 프린터 큐
문제 링크 : https://www.acmicpc.net/problem/19661966번: 프린터 ȕ...
blog.naver.com
문제 출처
1966번: 프린터 큐
여러분도 알다시피 여러분의 프린터 기기는 여러분이 인쇄하고자 하는 문서를 인쇄 명령을 받은 ‘순서대로’, 즉 먼저 요청된 것을 먼저 인쇄한다. 여러 개의 문서가 쌓인다면 Queue 자료구조에
www.acmicpc.net
'C' 카테고리의 다른 글
#69. [백준_C언어] 4889 : 안정적인 문자열 \ 자료구조 (0) | 2021.02.09 |
---|---|
#68. [백준_C언어] 1021 : 회전하는 큐 \ 자료구조 (0) | 2021.02.09 |
#66. [백준_C언어] 18258 : 큐 2 \ 큐, 덱 (0) | 2021.02.08 |
#65. [백준_C언어] 10773 : 제로 \ 스택 (0) | 2021.02.08 |
#64. [백준_C언어] 11866 : 요세푸스 문제 0 (0) | 2021.02.03 |