-
Notifications
You must be signed in to change notification settings - Fork 0
/
josefu.cpp
67 lines (62 loc) · 913 Bytes
/
josefu.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
#include<stdio.h>
using namespace std;
struct Node
{
int data;
Node* next;
};
void josefu(int n,int m)
{
Node *head=new Node;
head->next=NULL;
head->data=1;
Node *s=head;
for(int i=2;i<=n;i++)
{
Node *p=new Node;
p->data=i;
p->next=NULL;
s->next=p;
s=s->next;
}
s->next=head;
Node *p=head;
cout<<"输入的顺序为:"<<endl;
for(int j=1;j<=n;j++)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
p=head;
cout<<"输出的顺序为:"<<endl;
while(p)
{
for(int k=1;k<m-1;k++)
{
p=p->next;
}
cout<<p->next->data<<" ";
Node*s=p->next;
p->next=s->next;
s->next=NULL;
delete s;
p=p->next;
}
cout<<endl;
}
int main()
{
char key;
while(key!='n')
{
int n,m;
cout<<"请输入总人数n和m:"<<endl;
cin>>n>>m;
josefu(n,m);
cout<<"continue:y"<<" "<<"exit:n"<<endl;
cin>>key;
}
return 0;
}