import java.util.Collections
import java.util.List
import java.util.Random
public class Main {
public static void main(String[] args) {
//红球 33 选6
List<Integer> redBall = new ArrayList<Integer>()
for(int i=0i<33i++){
redBall.add(i+1)
}
System.out.println("开奖红球:" + select(redBall, 6))
//篮球16选1
List<Integer> blueBall = new ArrayList<Integer>()
for(int i=0i<16i++){
blueBall.add(i+1)
}
System.out.println("开奖蓝球:" + select(blueBall, 1))
}
public static List<Integer> select(List<Integer> list,int count){
List<Integer> selectedList = new ArrayList<Integer>()
Random random = new Random()
for(int i=0i<counti++){
int index = random.nextInt(list.size())
Integer number = list.get(index)
selectedList.add(number)
list.remove(index)
}
Collections.sort(selectedList)
return selectedList
}
}
#include<stdio.h>void main()
{
int a[]={1,2,3,4,5,6,7}
int b[7],i,j,count=0,max=0,maxflag
for(i=0i<7i++)
scanf("%d",&b[i])
i=0
while(i<7)
{
j=0
count=0
if(b[i]==a[j])
while(i<7 && j<7 && b[i]==a[j]) i++,j++,count++
else
i++
if(max<count) {max =countmaxflag=i}
}
count = max
if(count==7) printf("特等奖\n")
else if(count==6)
{
if(maxflag==7)
printf("二等奖\n")
else
printf("一等奖\n")
}
else if(count==5)
{
if(maxflag==7)
printf("三等奖\n")
else
printf("二等奖\n")
}
else if(count==4)
{
if(maxflag==7)
printf("四等奖\n")
else
printf("三等奖\n")
}
else if(count==3)
{
if(maxflag==7)
printf("五等奖\n")
else
printf("四等奖\n")
}
else if(count==2 && maxflag!=7)
printf("五等奖\n")
else
printf("没中奖\n")
}
新建一个单窗体的工程,在上面画出七个TEXTBOX,最好是一个控件数组,这样编程时容易控制,再建一个COMMOND BUTTON,将CAPTION改为“随机产生”。在程序运行后,每点击一下COMMAND1,将随机产生一组数字并按从小到大的顺序显示在文本框中。下面就是程序部分:Dim NumArray(1 To 7) As Integer′通用中定义Private Sub Command1_Click()
Dim i, j, N As Integer
For i = 1 To 7
NumArray(i) = 0
Next i
Randomize
NumArray(1) = Fix(1 + 32 * (Rnd()))
j = 1
Do
N = Fix(1 + 32 * (Rnd()))
For i = 1 To j
If N = NumArray(i) Then
Exit For ′重复时
ElseIf i = j Then ′未重复时
NumArray(i + 1) = N
j = j + 1
Exit For
End If
Next i
Loop While j <7
PopSort ′升序排列
For i = 1 To 7
Text1(i - 1).Text = NumArray(i)
Next i
End Sub
Private Sub PopSort() ′气泡排序法
Dim i, j, Temp As Integer
For i = 7 To 2 Step -1
For j = 7 - 1 To 1 Step -1
If i >= 7 - j + 1 Then
If NumArray(j + 1) <NumArray(j) Then
Temp = NumArray(j)
NumArray(j) = NumArray(j + 1)
NumArray(j + 1) = Temp
End If
End If
Next j
Next i
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)