用c语言实现约瑟夫环
正好之前写过基础的约瑟源码约瑟源代约瑟夫环,稍作修改就可以满足你的夫环夫环新加坡发卡网源码题目#include <stdio.h>#include <stdlib.h>
typedef struct _node {
int id;
int key;
struct _node *next;
} Linklist;
int main() {
int n, m;
scanf("%d %d", &n, &m);
int i, count = 0;
Linklist *head = (Linklist*)malloc(sizeof(Linklist)), *tail = head;
head->id = 1;
scanf("%d", &head->key);
head->next = head;
for(i = 2; i <= n; i++) {
Linklist *p = (Linklist*)malloc(sizeof(Linklist));
p->id = i;
scanf("%d", &p->key);
p->next = head;
tail->next = p;
tail = p;
}
while(head != tail) {
if(++count % m) {
tail = head;
} else {
m = head->key;
count = 0;
printf("%d ", head->id);
tail->next = head->next;
free(head);
}
head = tail->next;
}
printf("%d\n", head->id);
free(head);
return 0;
}
2024-12-28 23:59
2024-12-28 23:52
2024-12-28 22:31
2024-12-28 22:29
2024-12-28 22:01