Problem description:
With n personsSitting around in a circle, the number of people who count to m is displayed, and then the next person in the column starts to report again, and the number of people who count to m is displayed again, until all users are listed. output in the column-out order.
//******************************
// Description: Joseph Ring
// Class Name: Joseph
// Author: Hong Xiaojun
// Time: 2004-12-27
//******************************
1 Public Class Joseph PHAs
2 {
3 // Starts counting from the start user, and records the columns cyclically in the units of alter. The total number is total.
4 Public Int [] JOSE ( Int Total, Int Alter, Int Start)
5 {
6 Int I, J, K = 0 ;
7
8 // The Count array stores the data in the column-out order.
9 Int [] Count = New Int [Total + 1 ];
10
11 // S array to store initial data
12 Int [] S = New Int [Total + 1 ];
13
14 // Assign an initial value to array S. The first person serial number is 0, and the second person is 1.
15 For (I = 0 ; I < Total; I ++ )
16 {
17S [I]=I;
18}
19
20 // Stores data in the array count in the order of Columns
21 For (I = Total; I > = 2 ; I -- )
22 {
23 Start = (Start + Alter - 1 ) % I;
24 If (Start = 0 )
25 Start = I;
26 Count [k] = S [start];
27 K ++ ;
28 For (J = Start + 1 ; J <= I; j ++ )
29 S [J - 1 ] = S [J];
30 }
31
32 Count [k] = S [ 1 ];
33
34 // Result returned
35 Return Count;
36 }
37 }
AboveProgramBoth Microsoft Visual Studio. NET 2003 and Visual C #2005 express edition beta1 have been debugged.