using namespace std;
typedef struct
{
int o;
}Name;
typedef struct
{
Name *p;
int length;
}Person;
Person Found(int m);
void Remove(Person &a_,int m_,int k_);
int main()
{
int n = 0 , m = 0 , k = 0;
cout << "请输入人员个数n=";
cin>>n;
cout<<"请输入剔除一人的间距m=";
cin>>m;
cout<<"请输入剔除开始从第k为人,k=";
cin>>k;
Person a;
cout<<""<<endl;
a=Found(n);
cout<<""<<endl;
Remove(a,m,k);
return 0;
}
Person Found(int n_)
{
Person a;
for(int i=0;i<n_;i++)
{
cout<<""<<endl; //此处出问题
cout<<a.p[i].o<<""<<endl; //此处没有问题,没有初值,输出随机数
a.p[i].o=i+1;
cout<<""<<endl;
}
a.length=n_;
return a;
}
void Remove(Person &a_,int m_,int k_)
{
int q=k_-1,s=1,w=a_.length-1;
for(int i=0;i<w;i++)
{
while(1) //a_.p[q].k!=-1
{
if(a_.p[q].o!=-1)
{
if(s%m_==0)
{
a_.p[q].o=-1;
break;
}
s++;
}
q=(q+1)%(a_.length+1);
cout<<""<<endl;
}
q=(q+1)%(a_.length+1);
cout<<""<<endl;
cout<<"最后一位人为"<<a_.p[q].o<<endl;
}
for(int j=0;j<a_.length;j++)
if(a_.p[j].o!=-1)
cout<<"最后一位人为"<<a_.p[j].o<<endl;
}