#include "stdio.h"
main()
{int i,j,k,m,n
long int count=0
for(i=1i<=15i++)
for(j=i+1j<=15j++)
for(k=j+1k<=15k++)
for(m=k+1m<=15m++)
for(n=m+1n<=15n++)
{if(iden(i,j,k,m,n))
printf("No %ld : %5d%5d%5d%5d%5d\n",++count,i,j,k,m,n)
if(count%45==0) getchar()
}
}
iden(int i,int j,int k,int m,int n)
{if(i==j||i==k||i==m||i==n||j==k||j==m||j==n||k==m||k==n||m==n)
return 0
else
return 1
}
再增加两个变量,修改下程序可以35选5,我机子是P4 cpu1.8G 内存是512M,跑了好久,估计要两个小时左右!!!没耐心等下去,有朋友想试下的我把程序弄下面来了!!
#include "stdio.h"
main()
{int i,j,k,m,n,q,w
long int count=0
for(i=1i<=35i++)
for(j=i+1j<=35j++)
for(k=j+1k<=35k++)
for(m=k+1m<=35m++)
for(n=m+1n<=35n++)
for(q=n+1q<=35q++)
for(w=q+1w<=35w++)
{if(iden(i,j,k,m,n,q,w))
printf("No %ld : %5d%5d%5d%5d%5d%5d%5d\n",++count,i,j,k,m,n,q,w)
if(count%45==0) getchar()
}
}
iden(int i,int j,int k,int m,int n,int q,int w)
{if(i==j||i==k||i==m||i==n||i==q||i==w||j==k||j==m||j==n||j==q||j==w||k==m||k==n||k==q||k==w||m==n||m==q||m==w||n==q||n==w||q==w)
return 0
else
return 1
}
namespace Test{
class Program
{
static void Main(string[] args)
{
ICaiPiao cp = new CaiPiao()
List<int>numbers = cp.Extract()
string x = string.Empty foreach (int i in numbers)
{
x += " " + i.ToString()
}
Console.Write(x)
Console.Read()
}
}
interface ICaiPiao
{
List<int>Extract()
}
class CaiPiao : ICaiPiao
{
private List<int>numberspublic List<int>Extract()
{
List<int>numbers = new List<int>() NumberEntity[] ns = new NumberEntity[31]
for (int i = 0i <31i++)
{
ns[i] = new NumberEntity()
ns[i].Value = i + 1
ns[i].Selected = false
}
Random r = new Random()
do
{
int index = r.Next(0, 30)
if (!ns[index].Selected)
{
numbers.Add(ns[index].Value)
ns[index].Selected = true
}
} while (numbers.Count <7)
return numbers }
}
class NumberEntity
{
private int _Value public int Value
{
get { return _Value}
set { _Value = value}
}private bool _Selected public bool Selected
{
get { return _Selected}
set { _Selected = value}
}
}
}
我自己敲的 觉得好 就给点分把
#include <stdio.h>main()
{
int p[7],q[7],n,i/****p:投注号码,q:开奖号码****/
char c='0'
st(p,q)/****初始化****/
n=pd(p,q)
switch (n)
{
case 6:
{
if(p[6]==q[6]) c='!'
else c='1'
} break
case 5:
{
if(p[1]!=q[1]||p[4]!=q[4]) c='3'
if(p[2]!=q[2]||p[3]!=q[3]) c='0'
else c='2'
} break
case 4:
{
if((p[0]!=q[0]&&p[1]!=q[1])||(p[0]!=q[0]&&p[5]!=q[5])||(p[4]!=q[4]&&p[5]!=q[5]))
c='3'
else c='0'
}
}
switch (c )
{
case '!': printf("\nni zhong le te deng jiang!")break
case '1': printf("\nni zhong le 1 deng jiang!")break
case '2': printf("\nni zhong le 2 deng jiang!")break
case '3': printf("\nni zhong le 3 deng jiang!")break
case '0': printf("\nni mei you zhong jiang!")break
}
getch()
}
st(int p[],int q[])
{
int i
printf("\nXuan zhe tou zhu hao ma: ")
for(i=0i<7i++)
scanf("%d",&p[i])
printf("\nKai jiang hao ma shi: ")
for(i=0i<7i++)
scanf("%d",&q[i])
}
pd(int p[],int q[])
{
int i,n=0
for(i=0i<6i++)
if(p[i]==q[i])
n++
return(n)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)