11652: 카드

2022. 9. 29. 02:01C언어/백준

자료구조

브론즈 4

https://www.acmicpc.net/problem/11652

 

11652번: 카드

준규는 숫자 카드 N장을 가지고 있다. 숫자 카드에는 정수가 하나 적혀있는데, 적혀있는 수는 -262보다 크거나 같고, 262보다 작거나 같다. 준규가 가지고 있는 카드가 주어졌을 때, 가장 많이 가지

www.acmicpc.net

 

-결과

 

-코드

#include <stdio.h>

int main() {
	int cnt, n, m;
	int i, j, k;
	int arr[100] = { 0, };
 
	scanf("%d", &cnt);
 
	for (i = 0; i < cnt; i++) {
		scanf("%d %d", &n, &m);
		int ans = 1;
		int front = 0;
		int max = 0;
		for (j = 0; j < n; j++) {
			scanf("%d", &arr[j]);
        }
 
		while (1) {
			for (k = 0; k < n; k++) {
				if (arr[k] > max) max = arr[k];
			}
			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;
}

 

-풀이

이 문제는 원형 큐를 이용해서 풀어야 한다.

 

'C언어 > 백준' 카테고리의 다른 글

2675: 문자열 반복  (0) 2022.09.24
1764: 듣보잡  (0) 2022.09.24
18258: 큐 2  (0) 2022.09.24
3052: 나머지  (0) 2022.09.24
1158: 요세푸스 문제  (0) 2022.09.24