1.请C语言高手编程!“双色球”红号组合编程
2.ç¨Cè¯è¨ç¼ååè²ç代ç
请C语言高手编程!“双色球”红号组合编程
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int isLegal(int std[],双色源码建微商城int a[])
{
int sum=0;
int i,j;
for(i=0;i<6;i++)
for(j=0;j<6;j++)
{
if(a[i]==std[j])
sum++;
}
if(sum>3) return 0;
else return 1;
}
int isRepeated(int a[],int temp)
{
int i;
for(i=0; i<6; i++)
if(temp == a[i]) return 1;
return 0;
}
void main()
{
int randNumber[6]={ -1,-1,-1,-1,-1,-1},i,k,n,judge,temp;
int std[][6]={ { 1,5,6,,,},
{ 4,9,,,,},
{ 8,,,,,},
{ 5,8,,,,},
{ ,,,,,},
{ ,,,,,},
{ 6,9,,,,}
};
srand((unsigned)time(NULL));
printf("要产生几组这样的数? ");
scanf("%d",&n);
for(k=0;k<n;k++)
{
do{
judge=1;
for(i=0;i<6;i++)
{
do{
temp=rand()%+1;
} while(isRepeated(randNumber,temp));
randNumber[i]=temp;
}
for(i=0;i<7;i++)
{
judge*=isLegal(std[i],randNumber);
if(judge==0)
break;
}
}while(judge!=1);
for(i=0;i<6;i++)
printf("%d ",randNumber[i]);
printf("\n");
}
}