Archived
1
0
Fork 0
This repository has been archived on 2022-06-20. You can view files and clone it, but cannot push or open issues or pull requests.
mipt_clang/list_and_trees/lists/ejudge/joseph.c
nihonium 6161b74ffc new file: lists/double_linked_list.c
new file:   lists/ejudge/joseph.c
	new file:   lists/ejudge/joseph_full.c
	new file:   lists/ejudge/list3.c
	new file:   lists/ejudge/list3_full.c
	new file:   lists/list.c
	new file:   trees/tree1.c
	new file:   trees/tree2.c
	new file:   trees/tree2_full.c
	new file:   trees/tree4_full.c
2021-12-02 22:20:10 +03:00

37 lines
708 B
C

#include "../double_linked_list.c"
int main() {
int i;
int N ,M;
scanf("%d", &N);
scanf("%d", &M);
struct Node * a = malloc(sizeof(struct Node));
struct Node * res = malloc(sizeof(struct Node));
list_init(a);
list_init(res);
for(i=1; i<=N; i++) {
list_push_back(a, i);
}
struct Node *ptr = a->next;
struct Node *next = NULL;
while (ptr->next != ptr) {
for (i = 0; i < M-1; ++i) {
ptr = ptr->next;
if (ptr == a) {
ptr = ptr->next;
}
}
if (list_size(a) <= 3) {
list_push_back(res, ptr->data);
}
next = ptr->next;
list_delete(ptr);
ptr = next;
}
list_print(res);
while(list_delete(a->next) != -1);
while(list_delete(res->next) != -1);
free(a); free(res);
}