51. Play with beads

/*
8 5 3 2
1 5 6 4 3
2 6 3 5 4
3 3 4 6 5
4 4 5 3 6
5 5 6 4 3
1999%4=3
*/
#include "stdio.h"
void main()
{
int i,j,max;
int hz[4]={8,5,3,2},bh;
char hzm[4][5]={"A","B","C","D" };

for(i=1;i<=1999;i++)
{
//Find the number of the box with the most beads
max=hz[0];
bh=0;
for(j=0;j<=3;j++)
{
if(max<hz[j])
{
max=hz[j];
bh=j;
}
}

//take the beads
hz[bh]-=4;

//divide the beads
for(j=0;j<=3 ;j++)
{
hz[j]++;
}
}

for(i=0;i<=3;i++)
printf("%s:%d ",hzm[i],hz[i]);
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325790929&siteId=291194637