News outs

Question: Is there a personal circle, by serial number, the number of packets start from the first person, the number of the person to exit b, and the next re-start packet number from 1, to obtain a sequence of circle of people.

All Clear; Close All; CLC; 
in = INPUT ( 'the Enter A and B Separated by whitespace: \ n-', 'S'); 
T = Find (isspace becomes (in)); 
A = str2double (in (. 1: T- . 1)); 
B = str2double (in (T +. 1: length (in))); 
IF isNaN (A) || isNaN (B) 
    error ( 'the format error the Input: Enter Number Separated by whitespace TWO'); 
End 
X =. 1: a; 
Y = zeros (. 1, a); 
I =. 1; 
T = b; 
the while ~ isEmpty (X) 
    IF (T> length (X))% first input of a and b may be a <b, 
        MOD = t (t, length (X)); 
        iF t == 0% when b> length (x) when this situation occurs, it is necessary to correspond to the last element t 
            t = length (X); 
        End 
    End 
    Y (I) = X (T); 
    I = I +. 1; 
    X (T) = []; 
    T = T +. 1-b;% a number has been deleted, and then move back step b number number 
End 
DISP (Y);

  Note that if necessary extra step when b is greater than the remaining number, t = mod (t, length (x) represents a number of 0 to the last element of x.

Fun to write the algorithm is to consider a variety of special circumstances, and then solve!

Guess you like

Origin www.cnblogs.com/cq-shihao/p/11877121.html