回复 楼主 TAGC
import java.util.Random;
import java.util.Scanner;
class Group
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
Random randomNumber = new Random();
int n;
int i;
int j;
int a=0;
int b=0;
int c=0;
int d=0;
int e=0;
int[] array = new int [10];
System.out.print("请输入几人休假:");
n = in.nextInt();
for (i=1;i<=n ;i++ )
{
int number;
System.out.print("请输入第"+i+"休假人的编号:");
number = in.nextInt();
switch (i)
{
case 1:a = number;break;
case 2:b = number;break;
case 3:c = number;break;
case 4:d = number;break;
case 5:e = number;break;
}
}
switch (n)
{
case 0:
{
for (i=0;i<10 ;i++ )
{
array[i] = randomNumber.nextInt(10)+1;
for (j=0;j<i ;j++ )
{
if (array[i]==array[j])
{
array[i] = randomNumber.nextInt(10)+1;
j=-1;
}
}
}
for (i=0;i<10 ;i++ )
{
if (i/2==0)
{
if (i%2==0)
{
System.out.println("A:");
}
System.out.print(array[i]+" ");
if (i%2==1)
{
System.out.println();
}
}
if (i/2==1)
{
if (i%2==0)
{
System.out.println("B:");
}
System.out.print(array[i]+" ");
if (i%2==1)
{
System.out.println();
}
}
if (i/2==2)
{
if (i%2==0)
{
System.out.println("C:");
}
System.out.print(array[i]+" ");
if (i%2==1)
{
System.out.println();
}
}
if (i/2==3)
{
if (i%2==0)
{
System.out.println("D:");
}
System.out.print(array[i]+" ");
if (i%2==1)
{
System.out.println();
}
}
if (i/2==4)
{
if (i%2==0)
{
System.out.println("E:");
}
System.out.print(array[i]+" ");
if (i%2==1)
{
System.out.println();
}
}
}
}break;
case 1:
{
for(i=0;i<n;i++)
{
array[i] = a;
}
for(i=n;i<10;i++)
{
array[i] = randomNumber.nextInt(10)+1;
for (j=0;j<i ;j++ )
{
if (array[i]==array[j])
{
array[i] = randomNumber.nextInt(10)+1;
j=-1;
}
}
}
for (i=n;i<10 ;i++ )
{
if (i/2==0)
{
System.out.println("A:");
System.out.print(array[i]+" ");
if (i%2==1)
{
System.out.println();
}
}
if (i/2==1)
{
if (i%2==0)
{
System.out.println("B:");
}
System.out.print(array[i]+" ");
if (i%2==1)
{
System.out.println();
}
}
if (i/2==2)
{
if (i%2==0)
{
System.out.println("C:");
}
System.out.print(array[i]+" ");
if (i%2==1)
{
System.out.println();
}
}
if (i/2==3)
{
if (i%2==0)
{
System.out.println("D:");
}
System.out.print(array[i]+" ");
if (i%2==1)
{
System.out.println();
}
}
if (i/2==4)
{
if (i%2==0)
{
System.out.println("E:");
}
System.out.print(array[i]+" ");
if (i%2==1)
{
System.out.println();
}
}
}
}break;
case 2:
{
for(i=0;i<10;i++)
{
if(i==0)
array[i]=a;
else if(i==2)
array[i]=b;
else
{
array[i] = randomNumber.nextInt(10)+1;
for (j=0;j<i ;j++ )
{
if (array[i]==array[j]||array[i]==a||array[i]==b)
{
array[i] = randomNumber.nextInt(10)+1;
j=-1;
}
}
}
}
for (i=0;i<10 ;i++ )
{
if (i/2==0)
{
if (i%2==0)
System.out.println("A:");
if (i%2==1)
{
System.out.print(array[i]+" ");
System.out.println();
}
}
if (i/2==1)
{
if (i%2==0)
System.out.println("B:");
if (i%2==1)
{
System.out.print(array[i]+" ");
System.out.println();
}
}
if (i/2==2)
{
if (i%2==0)
{
System.out.println("C:");
}
System.out.print(array[i]+" ");
if (i%2==1)
{
System.out.println();
}
}
if (i/2==3)
{
if (i%2==0)
{
System.out.println("D:");
}
System.out.print(array[i]+" ");
if (i%2==1)
{
System.out.println();
}
}
if (i/2==4)
{
if (i%2==0)
{
System.out.println("E:");
}
System.out.print(array[i]+" ");
if (i%2==1)
{
System.out.println();
}
}
}
}break;
case 3:
{
for(i=0;i<10;i++)
{
if(i==0)
array[i]=a;
else if(i==2)
array[i]=b;
else if(i==4)
array[i]=c;
else
{
array[i] = randomNumber.nextInt(10)+1;
for (j=0;j<i ;j++ )
{
if (array[i]==array[j]||array[i]==a||array[i]==b||array[i]==c)
{
array[i] = randomNumber.nextInt(10)+1;
j=-1;
}
}
}
}
for (i=0;i<10 ;i++ )
{
if (i/2==0)
{
if (i%2==0)
System.out.println("A:");
if (i%2==1)
{
System.out.print(array[i]+" ");
System.out.println();
}
}
if (i/2==1)
{
if (i%2==0)
System.out.println("B:");
if (i%2==1)
{
System.out.print(array[i]+" ");
System.out.println();
}
}
if (i/2==2)
{
if (i%2==0)
{
System.out.println("C:");
}
if (i%2==1)
{
System.out.print(array[i]+" ");
System.out.println();
}
}
if (i/2==3)
{
if (i%2==0)
{
System.out.println("D:");
}
System.out.print(array[i]+" ");
if (i%2==1)
{
System.out.println();
}
}
if (i/2==4)
{
if (i%2==0)
{
System.out.println("E:");
}
System.out.print(array[i]+" ");
if (i%2==1)
{
System.out.println();
}
}
}
}break;
case 4:
{
for(i=0;i<10;i++)
{
if(i==0)
array[i]=a;
else if(i==2)
array[i]=b;
else if(i==4)
array[i]=c;
else if(i==6)
array[i]=d;
else
{
array[i] = randomNumber.nextInt(10)+1;
for (j=0;j<i ;j++ )
{
if (array[i]==array[j]||array[i]==a||array[i]==b||array[i]==c||array[i]==d)
{
array[i] = randomNumber.nextInt(10)+1;
j=-1;
}
}
}
}
for (i=0;i<10 ;i++ )
{
if (i/2==0)
{
if (i%2==0)
System.out.println("A:");
if (i%2==1)
{
System.out.print(array[i]+" ");
System.out.println();
}
}
if (i/2==1)
{
if (i%2==0)
System.out.println("B:");
if (i%2==1)
{
System.out.print(array[i]+" ");
System.out.println();
}
}
if (i/2==2)
{
if (i%2==0)
{
System.out.println("C:");
}
if (i%2==1)
{
System.out.print(array[i]+" ");
System.out.println();
}
}
if (i/2==3)
{
if (i%2==0)
{
System.out.println("D:");
}
if (i%2==1)
{
System.out.print(array[i]+" ");
System.out.println();
}
}
if (i/2==4)
{
if (i%2==0)
{
System.out.println("E:");
}
System.out.print(array[i]+" ");
if (i%2==1)
{
System.out.println();
}
}
}
}break;
case 5:
{
for(i=0;i<10;i++)
{
if(i==0)
array[i]=a;
else if(i==2)
array[i]=b;
else if(i==4)
array[i]=c;
else if(i==6)
array[i]=d;
else if(i==8)
array[i]=e;
else
{
array[i] = randomNumber.nextInt(10)+1;
for (j=0;j<i ;j++ )
{
if (array[i]==array[j]||array[i]==a||array[i]==b||array[i]==c||array[i]==d||array[i]==e)
{
array[i] = randomNumber.nextInt(10)+1;
j=-1;
}
}
}
}
for (i=0;i<10 ;i++ )
{
if (i/2==0)
{
if (i%2==0)
System.out.println("A:");
if (i%2==1)
{
System.out.print(array[i]+" ");
System.out.println();
}
}
if (i/2==1)
{
if (i%2==0)
System.out.println("B:");
if (i%2==1)
{
System.out.print(array[i]+" ");
System.out.println();
}
}
if (i/2==2)
{
if (i%2==0)
{
System.out.println("C:");
}
if (i%2==1)
{
System.out.print(array[i]+" ");
System.out.println();
}
}
if (i/2==3)
{
if (i%2==0)
{
System.out.println("D:");
}
if (i%2==1)
{
System.out.print(array[i]+" ");
System.out.println();
}
}
if (i/2==4)
{
if (i%2==0)
{
System.out.println("E:");
}
if (i%2==1)
{
System.out.print(array[i]+" ");
System.out.println();
}
}
}
}break;
}
}
}