// 创建循环链表,并获取每个人的密码key Node* head = createCircularList(n); Node* current = head; printf("请输入每个人的密码key:\n"); for (int i = 0; i < n; i++) { scanf_s("%d", ¤t->key); current = current->next; }
#include<stdio.h> #define N 100 intjosef(int a[], int n, int m) { int i, j, k = 0; for (i = 0; i < n; i++) { j = 1; while (j < m) { while (a[k] == 0) k = (k + 1) % n; j++; k = (k + 1) % n; } while (a[k] == 0) k = (k + 1) % n; printf("%d ", a[k]); a[k] = 0; } return0; } intmain() { int a[100]; int i, j, m, n; printf("请输入总人数n和初始报数上限m:"); scanf_s("%d%d", &n, &m); for (i = 0; i < n; i++) a[i] = i + 1; printf("\n key:\n"); josef(a, n, m); printf("\n"); return0; }