普通的 我也找到了一些不知道 到底 属于那类 #include<iostream.h> #include<iomanip.h>
struct josephus { int code; josephus * next; };
void main() { int number; int interal; cout<<"Please input the number of children: "; cin>>number; cout<<"Please input the interal of counting: "; cin>>interal; josephus * ptrJose=new josephus[number]; josephus * ptrCurrent=ptrJose; int count=0; cout<<"Now There are "<<number<<" in the queue:"; for(int i=1;i<=number;i++) { ptrCurrent->next=ptrJose+i%number; ptrCurrent->code=i; ptrCurrent=ptrCurrent->next; if(count++ % 10==0) cout<<endl; cout<<setw(4)<<i; } cout<<endl<<endl; josephus * pivot; ptrCurrent=&ptrJose[number-1]; while(ptrCurrent->next!=ptrCurrent) { for(int j=0;j<interal;j++) { pivot=ptrCurrent; ptrCurrent=ptrCurrent->next; } cout<<"NO."<<setw(4)<<ptrCurrent->code<<" is eliminated."<<endl; pivot->next=ptrCurrent->next; ptrCurrent=pivot; } cout<<endl; cout<<"The winner is "<<ptrCurrent->code<<endl<<endl; delete[] ptrJose; }