帮我备注一下这个C++程序

来源:百度知道 编辑:UC知道 时间:2024/07/12 02:31:37
struct Jose{
int code;
Jose* next;
};
int n,s,m;
Jose *pcur,*pivot;

bool getvalue();
Jose* createring();
void countboy();
void process();

int main()
{
if(!getvalue()) return 1;
Jose pjose =createring();
process();
cout<<"\nthe winner is " <<pcur->code<<"\n";

};

bool getvalue(){
cout<<" please input:\n";
cin>>n>>s>>m;
if(n<=2 && s<=1 && s<=n && m>=1 && m<=n) return true;
cerr<<"failed in bad boynumber or other.\n";
return false;
}
Jose* createring(){
Jose* px = new Jose[n];
for (int i=1;i<=n;++i)
{
px[i-1].next = &px[i%n];
px[i-1].code = i;
}
cout <<"there are "<<n<<"boys.\n";
pivot = &px[n-2];
pcur = &px[n-1];

#include <iostream.h>
//n个boy围成一圈,从第s个男孩开始,每次向后数m个男孩,一共数n次,看最后是哪一个男孩!
struct Jose{ //boy的结构体,相当于一个boy并给与编号
int code;
Jose* next;
};
int n,s,m; //n男孩总数,也是数的次数,s数数的起始位置,m每次的步长;
Jose *pcur,*pivot;//pcur当前男孩的指针位置,pviot不知道啥用,没有也可以

bool getvalue();//获得合理的输入,也就是n要大于s和m,并且都至少大于1
Jose* createring();//根据输入的数知道一个周长为n的循环队列,也就是让男孩围圈而坐
void countboy(int);//开始数数,这个函数是数一次的
void process();//这个是n次数数的全过程

int main()
{
if(!getvalue()) return 1;
Jose *pjose =createring();
process();
cout<<"\nthe winner is " <<pcur->code<<"\n";
return 0;
};

bool getvalue(){
cout<<" please input:\n";
cin>>n>>s>>m;
if(n>=2 && s>=1 && s<=n && m>=1 && m<=n) return true;
cerr<<"failed in bad boynumber or other.\n";
return false;
}