你们怎么老是树呀树的?我用普通算法完成了。
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
int m[30]={0};
enum team{A,B,C,D,E,F,G,H,I};
struct t{
char country[20];
team t;
}ct[32];
int *suiji(int n)
{
static int i=0;
int *p=&i;
while(i<n)
{
m[i]=rand()%n;
for(int j=0;j<i;j++)
if(m[j]==m[i])suiji(n);
i++;
}
return p;
}
main()
{
char a[][20]={"英格兰","意大利","葡萄牙","克罗地亚","土耳其","瑞典","捷克",
"塞尔维亚","加纳","科特迪瓦","突尼斯","尼日利亚","喀麦隆","日本","韩国",
"澳大利亚","伊朗","美国","墨西哥","哥斯达黎加","洪都拉斯","巴拉圭","智利",
"厄瓜多尔"};
char b[8][20]={"法国","德国","西班牙","荷兰","俄罗斯","巴西","阿根廷","乌拉圭"};
srand((unsigned) time(0));
team tt=A;
int flag=0;
int *p;
for(int i=0;i<32;i++)
{
if(i<8)
{
if(!flag)
{
p=suiji(8);
flag=1;
}
ct[i].t=(team)m[i];
strcpy(ct[i].country,&b[m[i]][0]);
ct[i].country[strlen(&b[m[i]][0])]='\0';
}
else
{
if(flag==1)
{
*p=0;
suiji(24);
flag=2;
}
ct[i].t=(team)(m[i-8]%8);
strcpy(ct[i].country,&a[m[i-8]][0]);
ct[i].country[strlen(&a[m[i-8]][0])]='\0';
}
}
flag=0;
for(int i=0,count=0;tt<=H&&i<32;i++)
{
if(ct[i].t==tt)
{
if(flag==0)
{
printf("%c:",tt+'A');
flag=1;
}
printf("%s ",ct[i].country);
count++;
if(count%4==0)
{
tt=(team)(tt+1);
i=-1;
flag=0;
printf("\n");
}
}
}
}