[BOJ] 11866 요세푸스 문제 0

Time Lapse :None

11866.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
int v[1001];
int main(void) {
int N, K, s = 1, c = 0, ss = 0;
scanf("%d %d", &N, &K);
printf("<");
while (c < N) {
while (ss < K) {
if (!v[s]) ++ss;
if (ss == K) break;
s = s + 1 > N ? 1 : s + 1;
}
v[s] = 1; ++c; ss = 0;
printf("%d", s);
if (c != N) printf(", ");
s = s + 1 > N ? 1 : s + 1;
}
printf(">");
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/11866/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.