Home > Back-end >  Urgent urgent Joseph ring, updated version
Urgent urgent Joseph ring, updated version

Time:09-22

N individual (numbered 1, 2, 3,... , n (n> 0)) clockwise around a circle, each holding a positive integer code, at the beginning of any given two values: a person for the first number off the serial number of the I (0 & lt; i<=n), and the other as the starting count off limits on m, then from the Numbers for the I began since 1 clockwise order number off, stop count off when reporting for m, and report to m people break the ranks, and his password as the new m values, in a clockwise direction from him on the next person to count off from 1,... Stand out and so on, until all the people, asked to design a program simulate this process, give dequeue serial number sequence,

CodePudding user response:

Can be done with a linked list

CodePudding user response:

Positive integer code is random values or given in advance? Using an array or a list simulation can,

CodePudding user response:

1) the number of n positive integers each password, count off one number for the first time I, on the initial count off limits m all by keyboard input,
2) respectively by sequential storage structure and chain store structure implementation of Joseph ring

CodePudding user response:

reference 1/f, Simple, Soft reply:
list can be used to implement
bosses can give the code

CodePudding user response:

Please refer to the
"C + + custom list implementation Joseph ring (2-1)"
"C + + custom list implementation Joseph ring (2-2)"
Wish I could help you!

CodePudding user response:

Write a simple period of using dynamic array simulation code, LZ can consult
Exception: every password is m, and the starting position for I 1 is the problem of original Joseph ring
 
Typedef struct {
The int value.
Int the key;
} Circle;

Int main () {
Int n, I, m, CNT, independence idx=0;
Printf (" please enter the total number of n: ");
The scanf (" % d ", & amp; N);
Circle * c=(Circle *) malloc (sizeof (Circle) * n);//application memory, dynamic array
for(i=0; iC [I] value=https://bbs.csdn.net/topics/1;//0 said out, said the game 1
Printf (" please enter the first % d personal password: ", I + 1);
The scanf (" % d ", & amp; C [I] key);
}
Printf (" please input the start position I (0 & lt; i<=n) : ");
The scanf (" % d ", & amp; I);
i--;//array subscript is location - 1
Printf (" please enter started to count off cap m: ");
The scanf (" % d ", & amp; M);
CNT=n;//the total number of game
While (cnt> 1) {
If (c [I] value=https://bbs.csdn.net/topics/=1) {
idx++;
}
If (independence idx==m) {
CNT -;//game number minus 1
C [I] value=https://bbs.csdn.net/topics/0;//out
M=c [I]. The key;//m is out of update password
Printf (" % d a dequeue coding: % d \ n ", n - CNT, (I + 1));
Independence idx=0;

}
i++;//I position increment
If (I==n) I=0;//if the location to circle the tail from scratch
}
For (; C [I]. value=https://bbs.csdn.net/topics/=0; I=(I + 1) % n);//find the last one didn't people out
Last dequeue number: printf (" % d \ n ", I + 1);
Free (c);//release the memory
return 0;
}

CodePudding user response:

reference 5 floor MianHou reply:

please reference"C + + custom list implementation Joseph ring (2-1)"
"C + + custom list implementation Joseph ring (2-2)"
Wish I could help you!
thank you!
  • Related