標題: 樂透測試 [打印本頁] 作者: ray 時間: 2011-12-3 20:12 標題: 樂透測試
import java.lang.*;
import java.util.*;
public class TQC101
{
int[] num;
public void init()
{
num = new int[42];
for(int i=0;i<42;i++)
num[i] = i+1;
}
public void random()
{
Random rnd = new Random((new Date()).getTime());
for(int i=0;i<42;i++)
{
int a = rnd.nextInt(42);
int b = rnd.nextInt(42);
int tmp = num[a];
num[a] = num[b];
num[b] = tmp;
}
}
public class Hello {
public static int gvar;
public static void say(String s) {
int x = 10;
System.out.print(s+x);
}
public static void main(String[] argv) {
float y = 0;
System.out.println("Hello, world\n");
}
}
class Lottery{
public static void main(String[] argv) {
Random rnd = new Random(new Date().getTime()) ;
Scanner in = new Scanner(System.in);
int user[] = new int [7];
int ans[] = new int [42];
int sum = 0 , special = 0;
for(int i=0;i<7;i++){
user[i] = in.nextInt();
}
System.out.print("Lottery number : ");
for(int i=0;i<42;i++){
ans[i] = i+1;
}
for(int i=0;i<42;i++){
int temp , temp1 , temp2;
temp1 = rnd.nextInt(42);
temp2 = rnd.nextInt(42);
temp = ans[temp1];
ans[temp1] = ans[temp2];
ans[temp2] = temp;
}
for(int i=0;i<6;i++){
System.out.print(ans[i]+" ");
for(int j=0;j<6;j++){
if(user[i] == ans[j]){
sum++;
}
}
}
System.out.println("Special number : "+ans[6]);
if(user[6] == ans[6]){
special = 1;
System.out.print("You got "+sum+" right number and a special number");
}else{
System.out.print("You got "+sum+" right number");
}