From the structure-oriented object ----- Josephus problem (method 1: array application)

xiaoxiao2021-03-06  39

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 1: A number of applications // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ # include

Void main () {int Num, Interval, * array; cout << "please input the number of chirlder:"; cin >> Num; if ((array = new int [num]) == null) {cout << "Can't instocate more memory, term"; exit (1);} for (int i = 0; i > Interval; IF (Interval <= Num && Interval> 0) Break;} for (int i = 0; I > i; I- = 2; while (1) {for (int J = 0; J

转载请注明原文地址:https://www.9cbs.com/read-71362.html

New Post(0)