#include<stdlib.h>
#include<ctime.h>
#include<stdio.h>
int main()
{
int a[1016][6],b[3],i,j;
int n1,n2,n3,m1,m2,m3;
char c;
srand( (unsigned)time( 0 ) );
for(i=0;i<1016;i++)
{
a[i][0]=rand()%33+1;
a[i][1]=rand()%33+1;
a[i][2]=rand()%33+1;
a[i][3]=rand()%33+1;
a[i][4]=rand()%33+1;
a[i][5]=rand()%33+1;
}
printf("按回车开始,输入'n'结束");
while((c=getchar())!='n')
{
b[0]=rand()%33+1;
b[1]=rand()%33+1;
b[2]=rand()%33+1;
printf("产生的随机组合数为%5d%5d%5d\n",b[0],b[1],b[2]);
for(j=0;j<1016;j++)
{
for(int a1=0;a1<6;a1++)
{
if(b[0]==a[j][a1])
{
m1=a[j][a1];
n1=1;
a[j][a1]=34;
break;
}
else
n1=0;
}
for(int a2=0;a2<6;a2++)
{
if(b[1]==a[j][a2])
{
m2=a[j][a2];
n2=1;
a[j][a2]=34;
break;
}
else
n2=0;
}
for(int a3=0;a3<6;a3++)
{
if(b[2]==a[j][a3])
{
m3=a[j][a3];
n3=1;
a[j][a3]=34;
break;
}
else
n3=0;
}
if(n1&&n2&&n3)
{
a[j][a1]=m1;
a[j][a2]=m2;
a[j][a3]=m3;
printf("查询的随机组合数在数组的第%d位置\n",j);
printf("6个数为:%5d%5d%5d%5d%5d%5d",a[j][0],a[j][1],a[j][2],a[j][3],a[j][4],a[j][5]);
break;
}
}
if((n1&&n2&&n3)==0)printf("你要的查的组合数未能找到,请继续!!\n");
}
return 0;
}
[
本帖最后由 hziee 于 2010-4-5 15:59 编辑 ]