알고리즘/SW Expert Academy

[D4] 7810. 승현이의 질문

혬혬 2019. 10. 6. 11:13
728x90
#include <stdio.h>
int input[500005] = { 0 };
int num;
void quickSort(int first, int last)
{
	int pivot;
	int i;
	int j;
	int temp;

	if (first < last)
	{
		pivot = first;
		i = first;
		j = last;

		while (i < j)
		{
			while (input[i] <= input[pivot] && i < last)
			{
				i++;
			}
			while (input[j] > input[pivot])
			{
				j--;
			}
			if (i < j)
			{
				temp = input[i];
				input[i] = input[j];
				input[j] = temp;
			}
		}

		temp = input[pivot];
		input[pivot] = input[j];
		input[j] = temp;

		quickSort(first, j - 1);
		quickSort(j + 1, last);
	}
}
int main() {
	int test_case = 0;
	scanf("%d", &test_case);
	char buffer = 0;
	scanf("%c", &buffer);
	for (int q = 0; q < test_case; q++) {
		int total_index = 0;
		scanf("%d", &total_index);
		for (int i = 0; i < total_index; i++)
			scanf("%d", &input[i]);
		quickSort(0, total_index-1 );
		int answer = 0;
		for (int i = total_index; i >=0; i--) {
			int box = total_index - i;
			if (i <= input[box]) {
				answer = i;
				break;
			}

		}
		printf("#%d %d\n", q + 1, answer);
	}

	return 0;
}
728x90