Today, I saw Josephus questions, suddenly I want to write some things, combined with my own thoughts, so I wrote these posts. Because there are a few code a bit long, I will be developed. If you have any help you have, I am gratifying. Maybe you will say that there is a lot of books in this question, but I am writing in different ways, so that beginners will experience the difference between the facing-oriented object; and you can also see what I wrote. And the differences in some books. If you are a prawn, you can smile, or enlighten me.
Josephus question: Several children are enclosed in a circle, from any child spacing M. The child will leave when every time to M-child, the child leaves. The last thing left is a winner. The first few is the winner?
/ / ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ / Method 2: Structure Application // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ # include
Struct jose {int code; jose * next;
Void mian () {int Numofboys, interval; cout << "please input the number of boys," << endl << "interval of counting:"; cin >> Numofboys >> interval
Jose * pjose = new jose [Numofboys]; Jose * pcurrent = pjose;
INT itemsinline = 0;
For (int i = 1; i <= numofboys; i ) {pcurrent-> next = pjose i% Numofboys; pcurrent-> code = i; pcurrent = pcurrent-> next;
IF (itemsinline % 10 == 0) cout << endl; cout << setw (4) << i;}
Itemsinline = 0;
Int Numofcount; cout << "please input:" endl; while (1) {cin >> Numofcount; if (0 Jose * pivot; pcurrent = & pjose [Numofcount-1]; While (pcurrent-> next! = pcurrent) {for (int J = 0; j IF (itemsinline % 10 == 0) cout << Endl; cout << setw (4) << pcurrent-> next; pivot-> next = pcurrent-> next; pcurrent = pivot; COUT << Endl << "The Winner IS:" << pcurrent-> code << Endl; delete [] pjose; }