-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw1_1
60 lines (54 loc) · 1.09 KB
/
hw1_1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include<stdlib.h>
#define MAXSIZE 3000
typedef struct
{
int* data;
int maxsize;
int length;
}Sqlist;
void InitList(Sqlist* l, int max)
{
l->maxsize = max;
for (int i = 0; i < l->maxsize; i++)
{
l->data[i] = i + 1;
}
l->length = l->maxsize;
}
void list_destroy(Sqlist* l, int num)
{
for (int i = num; i < l->length; i++)
{
l->data[i-1] = l->data[i];
}
l->length--;
}
int main(void)
{
int n, p;
scanf("%d", &n);
scanf("%d", &p);
Sqlist people;
people.data = (Sqlist* )malloc (MAXSIZE * sizeof(int));
InitList(&people, n);
//要考虑到n小于p的情况 可以对p进行取模运算;
int add = p;
while (people.length > 0)
{
if (people.length < p)
{
p = p % people.length ;
if (p == 0)
{
p = people.length;
}
}
printf("%d ", people.data[p-1]);
int ans = people.data[p-1];
list_destroy(&people, p );
p = p + add - 1 ;
}
free(people.data);
return 0;
}