[문제링크] : 링크텍스트
[문제링크] : 링크텍스트
#include <stdio.h>
int main(void)
{
int cnt, n, m;//케이스,정수변수 선언
int arr[100] = { 0 };//문자열 초기화
scanf("%d", &cnt);//테스트 케이스의 수 입력
for (int i = 0; i < cnt; i++) {
scanf("%d %d", &n, &m);//정수 N M 입력
int ans = 1;
int front = 0;
int max = 0;
//우선 순위 입력받기
for (int j = 0; j < n; j++)
scanf("%d", &arr[j]);//중요도 입력
while (1)
{//최댓값 찾기
for (int k = 0; k < n; k++) {
if (arr[k]>max)
max = arr[k];
}
//최댓값을 찾을때까지 front 이동
while (arr[front] != max)
front = (front + 1) % n;
if (front == m)
break;
arr[front] = 0;
front = (front + 1) % n;
max = 0;
ans++;
}
printf("%d\n", ans);//문서 차례 출력
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define MAX_QUEUE_SIZE 100
typedef int element;
typedef struct {
int front;
int rear;
element data[MAX_QUEUE_SIZE];
}QueueType;
void error(char* message)
{
fprintf(stderr, "%s\n", message);
exit(1);
}
void init_queue(QueueType* q)
{
q->front = -1;
q->rear = -1;
}
int is_full(QueueType* q)
{
if (q->rear == MAX_QUEUE_SIZE - 1)
return 1;
else
return 0;
}
int is_empty(QueueType* q)
{
if (q->front == q->rear)
return 1;
else
return 0;
}
void enqueue(QueueType* q, int item)
{
if (is_full(q))
{
error("full");
return;
}
q->data[++(q->rear)] = item;
}
int dequeue(QueueType* q)
{
if (is_empty(q))
{
printf("emty\n");
}
else {
int item = q->data[++(q->front)];
return printf("%d\n", item);
}
}
int main(void)
{
QueueType q;
init_queue(&q);
int i = 0, n, num;
char select;
scanf("%d",&n);
while (i < n)
{
scanf("%c", &select);
if (select == '1') /*1 num 입력시 정수 num을 enqueu*/
{
scanf("%d", &num);
enqueue(&q, num);
i++;
}
else if (select == 'o') /*o 입력시 dequeue*/
{
dequeue(&q);
i++;
}
else if (select == 'o')
{
printf("%d\n", (q.rear - q.front)); /*'o' 입력 시 큐에 있는 데이터 개수 출력*/
i++;
}
}
return 0;
}