Skip to content

Instantly share code, notes, and snippets.

@flyfire
Created October 6, 2013 14:02
Show Gist options
  • Select an option

  • Save flyfire/6854473 to your computer and use it in GitHub Desktop.

Select an option

Save flyfire/6854473 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int m,n,i,j;
printf("输入人数:");
scanf("%d",&n);
scanf("%*[^\n]");
int *a = (int *)malloc(sizeof(int) * n);
for (i = 0; i < n; i++)
{
a[i] = i+1;
printf("%4d",a[i]);
}
putchar('\n');
printf("第几个人出列:");
scanf("%d",&m);
scanf("%*[^\n]");
int pointer = 0;
for (i = n; i>0 ; i--)
{
pointer = (pointer+m-1) % i;
printf("%4d",a[pointer]);
for (j = pointer ; j <i-1 ; j++)
{
a[j] = a[j+1];
}
}
free(a);
a = NULL;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment