[KOI]전국본선 2013 중등부 두번째 문제




#include <stdio.h>

int main()
{
	int n;
	int after[30] = { 0, }, before[30] = { 0, };
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &after[i]);
	}
	int cur = 0, count = 0;
	while (count < n) {
		while (before[cur] != 0) {
			cur = (cur + 1) % n;
		}
		before[cur] = after[count++];
		cur = (before[cur] + cur) % n;
	}

	printf("%d\n", n);
	for (int i = 0; i < n; ++i) {
		printf("%d ", before[i]);
	}

	return 0;
}


설정

트랙백

댓글