本帖最后由 java2000_net 于 2008-08-05 13:16:05 编辑

解决方案 »

  1.   

    public class FenFeiQi{
      FenFeiQi(甲队,乙队){
        ...
      }  public void 分配(){
        for(甲队成员 p : 甲队){
             p.apply(乙队);//甲队成员可以接受乙队哪些成员
         }
          甲队成员C =min(甲队);
           递归(甲队, c);
           
        } private 甲队成员 min(甲队){//找出甲队中可以接受乙队成员最小的那个甲队成员
           .....
      }  private 甲队剩下成员 sub(甲队,甲队成员 c){//去掉这个甲队成员,剩下的甲队成员
         。。
     } private void 递归(甲队,甲队成员 c){
        
         println(c.name()+":"+c.defense());
         甲队剩余成员 =sub(甲队,c);
         if(甲队剩余成员.size()==0){//没有剩余了
             reutrn;
          }
         甲队成员B =min(甲队剩余成员);     递归(甲队剩余成员,B);
     }}使用:FenFeiQi t=new FenFeiQi(甲队,乙队);
     t.分配();
     
      

  2.   

    public class PingPang {    /**
         * 返回甲队的参赛选手名单
         * 
         * @param String[]
         *            one
         * @param String[]
         *            two
         * @return List<String>
         * @author guoqiang <[email protected]>
         */
        public static List<String> getSubmitOne(String[] one, String[] two) {        List<String> submitOne = new ArrayList<String>();        for (int i = 0; i < one.length; i++) {
                boolean bOne = true;
                for (int j = 0; j < two.length; j++) {
                    if (("a".equals(one[i]) && "x".equals(two[j])) || ("c".equals(one[i]) && "x".equals(two[j]))
                            || ("c".equals(one[i]) && "z".equals(two[j]))) {
                        bOne = false;
                    }
                }
                if (bOne)
                    submitOne.add(one[i]);
            }        return submitOne;
        }    /**
         * 返回乙队的参赛选手名单
         * 
         * @param String[]
         *            two
         * @return List<String>
         * @author guoqiang <[email protected]>
         */
        public static List<String> getSubmitTwo(String[] two) {        List<String> submitTwo = new ArrayList<String>();        for (int i = 0; i < two.length; i++) {
                submitTwo.add(two[i]);
            }        return submitTwo;
        }    /**
         * 打印出甲乙兩隊的參賽選手名單
         * 
         * @param List
         *            <String> submitOne
         * @param List
         *            <String> submitTwo
         * @return
         * @author guoqiang <[email protected]>
         */
        public static void printSubmitInfo(List<String> submitOne, List<String> submitTwo) {        System.out.println("甲队参赛名单为: " + submitOne.toString());        System.out.println("乙队参赛名单为: " + submitTwo.toString());
        }    /**
         * main主函数
          * 
         * @param args
         * @return
         * @author guoqiang <[email protected]>
         */
        public static void main(String[] args) {        String[] one = { "a", "b", "c" };
            String[] two = { "x", "y", "z" };        List<String> submitOne = getSubmitOne(one, two);
            List<String> submitTwo = getSubmitTwo(two);        printSubmitInfo(submitOne, submitTwo);
        }}
      

  3.   

    public class Match {
    public static void main (String args[]){
    String[] strArray1 = {"a", "b", "c"};
    String[] strArray2 = {"x", "y", "z"};

    label1: for (int i=0; i<strArray1.length; i++){
    label2: for(int j=0; j<strArray2.length; j++){
    if (((((strArray1[i] == "a") && (strArray2[j] == "x")))||(((strArray1[i] == "c") && (strArray2[j] == "x"))))||(((strArray1[i] == "c") && (strArray2[j] == "y"))))
    continue label2;
    else{
    System.out.print(strArray1[i] +":"+ strArray2[j] +" ");
    continue label1;
    }
    }
    }
    }
    }a:y b:x c:z 
      

  4.   


      public static void main(String[] args) {
        String[][] str = new String[3][3];
        String[] str1 = new String[] { "A", "B", "C" };
        String[] str2 = new String[] { "x", "y", "z" };
        for (int i = 0; i < str1.length; i++) {
              for (int j = 0; j < str2.length; j++) {
        if ((str1[i].equals("A") && str2[j].equals("x")) || 
        (str1[i].equals("C") && (str2[j].equals("x") || str2[j].equals("z")))) {
    str[i][j] = "0";
         } else {
    str[i][j] = "1";
         }
      }
    }
         Set<String> set = new HashSet<String>();
         for (int i = 0; i < str[0].length; i++) {
      String strResult = "";
      set.clear();
      if (str[0][i].equals("1")){
        set.add(str2[i]);
        strResult = str1[0] + ":" + str2[i] + "\t";
        for (int j = 0; j < str[1].length; j++) {
          if (str[1][j].equals("1") && !set.contains(str2[j])){
    set.add(str2[j]);
    strResult = strResult + str1[1] + ":" + str2[j] + "\t";
    for (int k = 0; k < str[2].length; k++) {
      if (str[2][k].equals("1") && !set.contains(str2[k])){
        set.add(str2[k]);
        strResult = strResult + str1[2] + ":" + str2[k];
        System.out.println(strResult);
      }
    }
          }
       }
     }
        }
      }
    来一个长点的,看晕了吧!
      

  5.   

    public static void main(String[] args) {        String[] one = { "a", "b", "c" };
            String[] two = { "x", "y", "z" };        String[] Results = new String[3];
            List<String> list = new ArrayList<String>();        for (String strTwo : two) {
                if (!"x".equals(strTwo) && !"z".equals(strTwo))
                    Results[2] = one[2] + ":" + strTwo;
                else
                    list.add(strTwo);
            }        for (String strTwo : list) {
                if (!"x".equals(strTwo))
                    Results[0] = one[0] + ":" + strTwo;
                else
                    Results[1] = one[1] + ":" + strTwo;
            }        System.out.println(Results[0] + '\t' + Results[1] + '\t' + Results[2]);
        }