|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
////////感谢小甲鱼老师,认真跟他学习才掌握了一些知识,
////////而且上课风趣幽默,希望大家能支持他,
////我也会支持他的!加油 鱼哥
#include <iostream>
struct node
{
int num;
int pass;
node* next;
}*head;
int getnodenum()
{
node *p;
p = head;
int i = 1;
p = p->next;
while(p != head)
{
p = p->next;
i++;
}
return i;
}
int main ()
{
node *p,*q;
head = new node;
p = head;
std::cout<< "请输入当前有几个人:\n";
int n;
std::cin>> n;
for(int i = 1; i <= n; i++)
{
q = new node;
q->num = i;
std::cout<< "请输入第 "<< i<<" 人的密码:\n";
std::cin>> q->pass;
p->next = q;
p = q;
}
p->next = head->next;
head = head->next;
p = head;
// deletenode(3);
// while(p != p->next)
// {
// std::cout<< "第 "<< p->num <<" 人的密码: "<< p->pass<< "->";
// p = p->next;
// }
int m;
std::cout<< "请输入开始人报数值:\n";
std::cin>> m;
while(p != p->next)
{
if(m >= 2)
{
for(int i = 2; i < m; i++)
{
p = p->next;
}
}
else if(m == 1)
{
for(int i = 1; i < getnodenum(); i++)
{
p = p->next;
}
}
else
{
std::cout<< "ERROR\n";
}
node *temp;
temp = p->next;
p->next = temp->next;
m = temp->pass + 1;
std::cout<< "第"<< temp->num<<"号出列-->";
delete temp;
}
std::cout<< "第"<< p->num<<"号出列\n";
}
Nightsong.cc我的博客 众位老大。。 |
|