#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define T League
typedef struct T *T;
#define TreeHeigh 5
char *Other[] = {"英格兰","意大利","葡萄牙","克罗地亚","土耳其","瑞典","捷克","塞尔维亚","加纳","科特迪瓦","突尼斯","尼日利亚","喀麦隆","日本","韩国","澳大利亚","伊朗","美国","墨西哥","哥斯达黎加","洪都拉斯","巴拉圭","智利","厄瓜多尔"};
char *Send[] = { "乌拉圭","西班牙","德国","阿根廷","荷兰","法国","巴西","俄罗斯"};
int F_Send[ 8 ];
int F_Other[ 24 ];
struct T{
int Score;
int Heigh;
T Left;
T Right;
char *Name;
};
void INIT( T *Root, int Heigh );
void Print( T Root );
int main( void )
{
T Root;
int heigh;
heigh = 0;
Root = NULL;
INIT( &Root, heigh );
Print( Root );
return 0;
}
void INIT( T *Root, int Heigh )
{
int f;
static int g = -1;
srand( ( unsigned )time( NULL ) );
if( NULL == *Root )
{
T new = ( T )malloc( sizeof( struct T ) );
if( NULL == new )
exit( EXIT_FAILURE );
new->Left = NULL;
new->Right = NULL;
new->Name = NULL;
new->Score = -1;
new->Heigh = Heigh;
*Root = new;
}
if( TreeHeigh == ( *Root )->Heigh )
{
++g;
if( 0 == g % 4 )
{
while( 1 )
{
f = rand( ) % 8;
if( 0 == F_Send[ f ] )
{
( *Root )->Name = Send[ f ];
F_Send[ f ] = 1;
break;
}
}
}
else
{
while( 1 )
{
f = rand() % 24;
if( 0 == F_Other[ f ] )
{
( *Root )->Name = Other[ f ];
F_Other[ f ] = 1;
break;
}
}
}
}
if( TreeHeigh == Heigh )
return;
INIT( &(*Root)->Left, Heigh + 1 );
INIT( &(*Root)->Right, Heigh + 1 );
}
void Print( T Root )
{
static int g = 0;
static char ch = 'A';
if( NULL == Root )
return;
if( NULL != Root->Name )
{
if( 0 == g % 4 )
printf( "%c\n", ch++);
printf( "%s ", Root->Name );
++g;
if( 0 == g % 2 )
printf( "\n" );
}
Print( Root->Left );
Print( Root->Right );
}