⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lotto.cpp

📁 樂透選號小程式
💻 CPP
字号:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>


int main(void)
{
	int num[6],i,j,k,a,b;
	int chz_set,n_th,chz_num[10][6],count,repeat;
	int com_num[10][6];
	char select,exit;
	srand(time(NULL));
do{		
	
	printf("artificial or computer (A/C)?");
	scanf("%s",&select);
	
//=============================the resultant set start==========================	
	
		printf("the resultant set is:");
	
		for(i=0;i<=5;i++) //choose six number
		{
		num[i]=(rand()%49)+1; //random number from 1 to 49
			for(k=1;k<i;k++) //no repeat number
			{
			if(num[k]==num[i]) i--;
			}	
		}		
		for(i=0;i<=4;i++) //asceding ordered number
		{
			for(j=i+1;j<=5;j++)
				if(num[i]>num[j])
				{
				a=num[i];
				num[i]=num[j];
				num[j]=a;
				}
		}					
		for(i=0;i<=5;i++)
		printf("%d ",num[i]);
		printf("\n");
//============================the resultant set end=============================
if(select=='a'||select=='A')//artificial@artificial@artificial@artificial
//============================artificial number start===========================
{		
	printf("Input the number of set you will choose is :");
	scanf("%d",&chz_set);

	for(k=1;k<=chz_set;k++)//the set loop
	{
	    n_th=1;//the first number of set (not compare)
		do
		{
		printf("the %d-th number of %d-th set you choose is :",n_th,k);
		scanf("%d",&chz_num[k][n_th]);
		}while((chz_num[k][n_th]<=0)||(chz_num[k][n_th]>49));
			
			n_th=2;//the second number of set (has to compare with forward)
			while(n_th<=6)
			{
				do
				{
				printf("the %d-th number of %d-th set you choose is :",n_th,k);
				scanf("%d",&chz_num[k][n_th]);
				}while((chz_num[k][n_th]<=0)||(chz_num[k][n_th]>49));
				
				count=1;
				repeat=0;
				while(count<n_th) //no repeat number
				{
					if(chz_num[k][count]==chz_num[k][n_th]) 
					{
					repeat=1;
					}
					count++;
				}
				if(repeat==0) n_th++;
			}
	}

//=============================artificial number end============================

//======================the attificial result start=============================
	for(k=1;k<=chz_set;k++)
	{
		for(i=1;i<=5;i++) //asceding ordered number
		{
			for(j=i+1;j<=6;j++)
				if(chz_num[k][i]>chz_num[k][j])
				{
				b=chz_num[k][i];
				chz_num[k][i]=chz_num[k][j];
				chz_num[k][j]=b;
				}
		}					
	printf("the number of %d-th set you choose is : ",k);
		for(n_th=1;n_th<=6;n_th++) //print the number of k row
		{			
		printf("%d ",chz_num[k][n_th]);					
		}
	printf("\n");
	}
	
	for(k=1;k<=chz_set;k++) //print the hitting number of k set
	{	
		printf("the hitting number of %d-th set is :",k);
		for(n_th=1;n_th<=6;n_th++)
		{
			for(i=0;i<=5;i++)
			{
				if(chz_num[k][n_th]==num[i])
				{
				printf("%d ",chz_num[k][n_th]);
				}
			}
		}
		printf("\n");
	}	
//====================the attificial result end=================================
}
//artificial@artificial@artificial@artificial@artificial@artificial@artificial

if(select=='c'||select=='C')//computer@computer@computer@computer@computer@computer
//===============================computing number start=========================
{
	printf("Input the number of set you will choose is :");
	scanf("%d",&chz_set);

	for(k=1;k<=chz_set;k++)//the set loop
	{
		for(n_th=1;n_th<=6;n_th++)
		{
		printf("the %d-th number of %d-th set computer choose is :",n_th,k);	
		com_num[k][n_th]=(rand()%49)+1; //random number from 1 to 49
		printf("%d",com_num[k][n_th]);
		printf("\n");
		
			for(i=2;i<n_th;i++) //no repeat number
			{
				if(com_num[k][i]==com_num[k][n_th]) n_th--;
			}	
		}
	
		
	}
//===============================computing number end===========================

//======================the computing result start==============================
	for(k=1;k<=chz_set;k++)
	{
		for(i=1;i<=5;i++) //asceding ordered number
		{
			for(j=i+1;j<=6;j++)
				if(com_num[k][i]>com_num[k][j])
				{
				b=com_num[k][i];
				com_num[k][i]=com_num[k][j];
				com_num[k][j]=b;
				}
		}					
	printf("the number of %d-th set computer choose is : ",k);
		for(n_th=1;n_th<=6;n_th++) //print the number of k row
		{			
		printf("%d ",com_num[k][n_th]);					
		}
	printf("\n");
	}
	
	for(k=1;k<=chz_set;k++) //print the hitting number of k set
	{	
		printf("the hitting number of %d-th set is :",k);
		for(n_th=1;n_th<=6;n_th++)
		{
			for(i=0;i<=5;i++)
			{
				if(com_num[k][n_th]==num[i])
				{
				printf("%d ",com_num[k][n_th]);
				}
			}
		}
		printf("\n");
	}	
//====================the computing result end==================================
}
printf("continue? (Y/N)");
scanf("%s",&exit);

}while(exit=='y'||exit=='Y');
printf("Orz");
system("pause");
}
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -