#include <stdio.h> #include <string.h> #define N 100 int main() { int m, n, i, k = 1; scanf("%d",&n); scanf("%d",&m); int a[N] = {0}; for(i = 0; i < n; i++) a[i] = i+1; i=0; while (n > 1) { /********** Begin *********/ if(a[i]>0) { if(k!=m) { k++; i=(i+1)%n; } else { k=1; a[i]=0; i=(i+1)%n; n--; } } else { i=(i+1)%n; } // 请在此处添加你的代码 /********** End **********/ } printf("最后一个出列的是%d", a[i]); return 0; }
时间: 2023-07-23 16:10:00 浏览: 85
#include <stdio.h>
4星 · 用户满意度95%
#include <stdio.h>
#include <string.h>
#define N 100
int main()
{
int m, n, i, k = 1;
scanf("%d", &n);
scanf("%d", &m);
int a[N] = {0};
for (i = 0; i < n; i++)
a[i] = i + 1;
i = 0;
while (n > 1)
{
if (a[i] > 0)
{
if (k != m)
{
k++;
i = (i + 1) % n;
}
else
{
k = 1;
a[i] = 0;
i = (i + 1) % n;
n--;
}
}
else
{
i = (i + 1) % n;
}
}
printf("最后一个出列的是%d", a[i]);
return 0;
}
阅读全文