| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 520 人关注过本帖
标题:麻烦大家看看这个小程序怎样写?
只看楼主 加入收藏
TAGC
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-10-28
收藏
 问题点数:0 回复次数:1 
麻烦大家看看这个小程序怎样写?
   1,2,3,4,5,6,7,8,9,10分别代表10个人,A,B,C,D,分别代表5个小组。要求;
1、10个人随机分成5个组(A,B,C,D,E),每两个人一组;
2、如果1,3休假,其他8人随机分成5个组(A,B,C,D,E),每两个人一组,其中,A,B,C,D,E组可以自定义哪两个组安排且只安排1个人;
3、如果4,5,6休假,其他7人随机分成5个组(A,B,C,D,E),每两个人一组,其中,A,B,C,D,E组可以自定义哪3个组安排且只安排1个人;
4、以上休假的人数以及人的个体要求事先自定义;
5、最多5个人休假,其他5个人随机分成5个小组。

    看似简单,但对于几乎未接触过编程的我来说是一个很神秘的东西,麻烦大家帮个忙,把程序写下来并发到我邮箱里,谢谢!

    邮箱:mini-pig@
搜索更多相关主题的帖子: 麻烦 
2010-10-28 21:33
dengjinbao
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:64
专家分:119
注 册:2011-3-22
收藏
得分:0 
回复 楼主 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;
            
        
        }
        
    }
}
2011-03-23 22:05
快速回复:麻烦大家看看这个小程序怎样写?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022786 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved