Submission #14611

#TimeUsernameProblemLanguageResultExecution timeMemory
14611caphile98버블 정렬 (OJUZ10_bubblesort)C++98
0 / 100
1000 ms2256 KiB
#include <stdio.h>
#define MAX 100001
int arr[MAX];
int brr[MAX];
int check[MAX];

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);

	int i, j;
	for (i = 1; i <= n; i++)
	{
		scanf("%d", &arr[i]);
		brr[i] = arr[i];
	}
	int temp;
	int a = 0;
	int e = n;
	int l;
	for (i = 1; i <= k; i++)
	{
		for (j = 1; j < e; j++)
		{
			if (check[j] == 1 || check[j + 1] == 1)
				continue;
			if (arr[j]>arr[j + 1])
			{
				temp = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = temp;
			}
		}
		for (j = 1; j <= e; j++)
		{
			if (check[j] == 1)
				continue;
			if (arr[j] == brr[j])
			{
				check[j] = 1;
				a += 1;
				if (a == n)
				{
					for (l = 1; l <= n; l++)
						printf("%d ", arr[l]);
					return 0;
				}
			}
			brr[j] = arr[j];
		}
		e -= 1;
	}
	for (i = 1; i <= n; i++)
		printf("%d ", arr[i]);
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...