#include <stdio.h>
#include <stdlib.h>
struct list {
int data;
struct list* next;
};
typedef struct list* link;
void k_main(){
printf("报三退圈游戏,请输入总数:\n");
int n ;
scanf_s("%d", &n);
printf("开始报数\n");
int m = 0;
struct list* ptr, * head;
ptr = head = (link)malloc(sizeof(struct list));
for (int i = 0; i < n; i++) {
ptr->data = i + 1;
if (i == n - 1) {
ptr->next = head;
}
else {
ptr = ptr->next = (link)malloc(sizeof(struct list));
}
}
ptr = head;
while (ptr != (ptr->next)) {
m++;
printf("%d\n", ptr->data);
if (m == 2) {
printf("%d: kill\n", ptr->next->data);
(ptr->next) = ((ptr->next)->next);
m = 0;
}
ptr = ptr->next;
}
for (int i = 0; i < m; i++) {
}
printf("存留: %d", ptr->data);
}
09-03
09-11
05-07
3456
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交