Home > Back-end >  The great spirit show genuflect is begged!
The great spirit show genuflect is begged!

Time:09-28

Function: ten children in a circle of candy, teachers for the first 10 children,

A third child of eight second child 2 pieces, the fourth child 22, the fifth

Children 16 pieces, sixth child 4 piece, the seventh child 10, 8 children 6

, the ninth child 14, 20, 10 children and then all the children at the same time,

Will their sugar half to the left of the child; Candy bar the odd number of people to the teacher

Want a piece of, ask after adjusting for several times so everyone in the hands of sugar blocks are all the same? Each

Each how many lumps of sugar?

*/

# include & lt; stdio.h>

Void main ()

{

Int I, count=0, a [11]=,10,2,8,22,16,4,10,6,14,20 {0};

/* * * * * * * * * * * SPACE * * * * * * * * * * */

While ([?] )

{

For (I=1; I<=10; I++)

A [] I - 1=a [I - 1)/2 + a [I]/2;

A [10]=[10] a/2 + a, [0].

For (I=1; I<=10; I++)

/* * * * * * * * * * * SPACE * * * * * * * * * * */

If ([?] ) a [I] + +;

For (I=1; I<10; I++)

/* * * * * * * * * * * SPACE * * * * * * * * * * */

If (a [I]!=a [?] [I + 1)) ;

If (I==10)

break ;

The else

{

A [0]=0;

Count++;

}

}

Printf (" count=% d number=% d \ n ", the count, a [1]).

}

CodePudding user response:

 
# include & lt; stdio.h>
/* found that is odd, fill 1,
*/
Void add_odd (int a [], int num)
{
Int I=1;
for (; I & lt; Num. I++)
{
If (a [I] % 2!=0)
{
A [I] + +;
}

}
}
/* is equal to return 1, not equal to return 0, said still points */
Int check (int a [], int num)
{
Int equal=1;
Int I=1;
for (; I & lt; Num. I++)
{
If (a [I]!=a [1])
return 0;

}
Return equal;
}

Void main ()
{

Int I, count=0, a [11]={0, 10, 2, 8, 22, 16, 4, 10, 6, 14, 20};

/* * * * * * * * * * * SPACE * * * * * * * * * * */

While (1)
{
If (1==check (a, 11)) {
Printf (" count=% d number=% d \ n ", the count, a [1]).
break;
}

Add_odd (a, 11);//fill an odd number, could fill the equal,
If (1==check (a, 11)) {
Printf (" count=% d number=% d \ n ", the count, a [1]).
break;
}
/* * * * * * * * * * * * */
A [0]=0;//for a [0] is always used to hold a half [1]
For (I=1; I & lt; 11. I++) {
A [] I - 1=a [I - 1)/2 + a [I]/2;
}
A [10]=[10] a/2 + a, [0].
count++;
}
}
  • Related