-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSDUT 2056.cpp
47 lines (45 loc) · 924 Bytes
/
SDUT 2056.cpp
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
#include<iostream>
using namespace std;
typedef struct node
{
int data;
struct node *next;
}Node;
int main()
{
int n;
while(scanf("%d",&n),n!=0)
{
Node *head,*cur,*prev;
head = (Node*)malloc(sizeof(Node));
prev = head;
for(int i = 1;i<=n;i++)
{
prev->data = i;
if(i==n) break;
cur = (Node*)malloc(sizeof(Node));
prev->next = cur;
prev = cur;
}
prev ->next = head;
int cnt = 2;
prev = head;
cur = prev->next;
int num = 1;
while(cnt!=5||cur->data!=1)
{
if(cnt == 5)
{
cur = cur->next;
prev->next = cur;
cnt=1;
num++;
}
cnt++;
cur=cur->next;
prev = prev->next;
}
printf("%d\n",num);
}
return 0;
}