From facing-oriented object ----- Josephus expansion problem (2)

xiaoxiao2021-03-06  40

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 extension problem (2): A group of children enclose a circle, and the M numbers are counted in the clockwise direction. If you want the win, you will win, what kind of child wants to start from?

/ / ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /RING.H / / ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ struct node {int code; node * next;}; class ring {public: Ring (int N); ~ Ring (); void Progress (int M); void printnode (); int getCode (); void deletenode (); Protected: node * head; node * pivot; node * pcur;}; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ # include #include #include "ring.h" Ring :: rG (int N) ) {Head = new node [n]; pcur = head; for (int i = 1; i <= n; i , pcur = pcur-> next) {pcur -> code = i; pcur -> Next = head (I% N); // printnode (); // if you want to look the boy who was you input, you can live out "//"} cout << Endl; pcur = & head [n-1];} Ring :: ~ Ring () {delete [] head;} ​​void} {for (int i = 0; i next;} } void ring :: PrintNode () {static int linecount; if (((LINECount )% 10) == 0) COUT << Endl; cout << setw (4) << pcur -> code;} int} pcur -> code;} void ring :: deletenode () {pivot -> next = PCUR -> Next; PCur = Pivot;} // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~ Class Jose {public: Jose (int Boys, int Begin, Int m); Jose (); int getwinner (); protected: int number; int started: int number; }; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ // jose.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ # include

#include "ring.h" #include "jose.h" jose :: jose (int Boys, int start, int m) {ix (BOYS <1) {cout << "Bad Number of Boys! / N"; RETURN } IF (Begin <0) {cout << "Bad beginning position! / N"; return;} = ((M> <1) || (m> Boys)) {cout << "Bad Interval Number! / N "} Numofboys = BOYS; beginpos = begin; interval = m;} jose :: jose () {int BOYS, BEGIN, M; cout <<" please input the number of boys.then input the number which you want To begin count.The thirt: / n "; cin >> BOYS >> Begin >> m; IF (Boys <1) {cout <<" Bad Number of Boys! May BE, The Number IS TOO Small! / n "; return;}}} {cout <<" The value of the beginning number muşpi 1./n "; return;} = ((m <1) || (m> BOYS)) {cout << "Interval number is between 1 and number of boys"; return; numofboys = BOYS; beginpos = begin; interval = m;} int Jose :: getwinner () {RIN (Numofboys); x .Progress (beginpos-1); for (int i = 1; i

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

New Post(0)