Home > Back-end >  Help [C] n individuals in a circle cycle count off 1 ~ 3, eliminate reporting for 3 people, find out
Help [C] n individuals in a circle cycle count off 1 ~ 3, eliminate reporting for 3 people, find out

Time:04-13

 
Void main ()
{
Int people [1000], n_5;
Printf (" both Please enter the number of people: \ n ");
The scanf (" % d ", & amp; N_5);

for(int i=0; i{
People [I]=I + 1;
}
//printf (" people [4]=% d \ n ", people [4]);
Int * p_5=people;
Int remain=n_5 num_off=1;
While (remain> 1)//the rest of the Numbers is greater than 1
{

If ((p_5) & lt;=(people + n_5-1))//the man is not a number of the last
{
//printf (" p_5=% d ", p_5);

While ((* p_5)!=0)//this person not registered before 3
{

If (num_off!=3)//who count off for 3
{

Num_off + +;

}
Else if (num_off==3)//who count off for 3
{

* p_5=0;
Remain -;

Num_off=1;
}

Printf (" * p_5 num_off==% d % d \ n ", * p_5, num_off);//for observation process
P_5 + +;

}

}



Else if (p_5 & gt; (people + n_5-1))
{
P_5=people;
While ((* p_5)!=0)
{
If (num_off!
=3){
Num_off + +;

}
Else if (num_off==3)
{
* p_5=0;
Remain -;

Num_off=1;
}
P_5=people;
}


}
}

While ((* p_5)==0)
{

P_5 + +;
}
Printf (" The number of remained one is: % d \ n ", * p_5);
}


Here is the run results, trouble to help have a look, thank!

CodePudding user response:

Suggest their abilities of debugging and coding debugged, equally important, even more important

CodePudding user response:

Fyi:
//assume there are n people completely surrounded, personal start counting from the first, at the first m personal time, the first m personal dequeue, 
//and then continue to count from 1 began to count, to the first m personal exit
#include
#include
Int I, k, t;
int n,m;
The static char f [1001];//0 the seats are not ones, 1 the seat has been ones with
Void main () {
While (1) {
Printf (" Input n m (1000 & gt;=n>=m>=1) : ");
The fflush (stdout);
The rewind (stdin);
If (2==the scanf (" % d % d ", & amp; N, & amp; M)) {
If (1000 & gt;=n & amp; & N>=m & amp; & M>=1) break;
}
}
T=0;//have ones with the total number of
i=1;//seat number
k=1;//the current wants to count the number of
While (1) {
If (==0 f [I]) {
If (m==k) {
T++;
F [I]=1;
Printf (" % 3 d ", I);
If (0==t % 10) printf (" \ n ");
If (t>=n) break;
}
k++; If (k> M), k=1;
}
i++; If (i> N) I=1;
}
Cprintf (" Press any key... ");
getch();
}

CodePudding user response:

Reference:
 void main () 
{
Int people [1000], n_5;
Printf (" both Please enter the number of people: \ n ");
The scanf (" % d ", & amp; N_5);

for(int i=0; i{
People [I]=I + 1;
}

Int * p_5=people;
Int remain=n_5 num_off=0;
While (remain> 1)//the rest of the Numbers is greater than 1
{
P_5=people;//here is equivalent to the end to end of an array is
While ((p_5) & lt;=(people + n_5-1))//determine whether in the array, to tail jump out to a
{//this cycle is the length of a n

If (* p_5!=0)//judgment to have ones, if you have ones with the skip, enter p_5 + + a data judgment
{
Num_off + +;//not ones to count 1

If (num_off==3)
{
Printf (" this is a registration number 3: * p_5 num_off==% d % d \ n ", * p_5, num_off);//for observation process
* p_5=0;
Remain -;//the total number of minus one
Num_off=0;//start from 0 to count
}
}
//printf (" * p_5 num_off==% d % d \ n ", * p_5, num_off);//for observation process
P_5 + +;//array under a data
}
}

P_5=people;//right now to make p_5 array pointer back to the first position

While (* p_5==0)//find the location of the last is not zero
P_5 + +;
Printf (" The number of remained one is: % d \ n ", * p_5);

}

CodePudding user response:

reference 1st floor flying_music response:
suggest their debugging, debugging with coding ability is just as important, even more important

Know, thank you! This is already a lot of times, or not??

CodePudding user response:

refer to the second floor 4 teacher zhao response:
are for reference only:
//assume there are n people completely surrounded, personal start counting from the first, at the first m personal time, the first m personal dequeue, 
//and then continue to count from 1 began to count, to the first m personal exit
#include
#include
Int I, k, t;
int n,m;
The static char f [1001];//0 the seats are not ones, 1 the seat has been ones with
Void main () {
While (1) {
Printf (" Input n m (1000 & gt;=n>=m>=1) : ");
The fflush (stdout);
The rewind (stdin);
If (2==the scanf (" % d % d ", & amp; N, & amp; M)) {
If (1000 & gt;=n & amp; & N>=m & amp; & M>=1) break;
}
}
T=0;//have ones with the total number of
i=1;//seat number
k=1;//the current wants to count the number of
While (1) {
If (==0 f [I]) {
If (m==k) {
T++;
F [I]=1;
Printf (" % 3 d ", I);
If (0==t % 10) printf (" \ n ");
If (t>=n) break;
}
k++; If (k> M), k=1;
}
i++; If (i> N) I=1;
}
Cprintf (" Press any key... ");
getch();
}

Ok, thank you!

CodePudding user response:

The
reference 3 floor QZJHJXJ response:
for reference:
 void main () 
{
Int people [1000], n_5;
Printf (" both Please enter the number of people: \ n ");
The scanf (" % d ", & amp; N_5);

for(int i=0; i{
People [I]=I + 1;
}

Int * p_5=people;
Int remain=n_5 num_off=0;
While (remain> 1)//the rest of the Numbers is greater than 1
{
P_5=people;//here is equivalent to the end to end of an array is
While ((p_5) & lt;=(people + n_5-1))//determine whether in the array, to tail jump out to a
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related