两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单

解决方案 »

  1.   

    int a, b, c;
    for (a = 1; a <= 3; a++) {//穷举A的所有对手
    for(b = 1; b <= 3; b++){//穷举B的所有对手
    for(c = 1; c <= 3; c++){//穷举C的所有对手
    if(a!=1 && c!=1 && c!=3 && a!=b && b!=c && c!=a){//满足题目条件的情况
    System.out.println("A VS " + (char)('X'+a-1));
    System.out.println("B VS " + (char)('X'+b-1));
    System.out.println("C VS " + (char)('X'+c-1));
    }
    }
    }
    }

      

  2.   

    好像不对
    这样输出就是123了,不是xyz还要加些什么11
      

  3.   

     if(a!=1 && c!=1 && c!=3 && a!=b && b!=c && c!=a){//满足题目条件的情况
    这句也有问题
      

  4.   

    (char)('X'+a-1)
    这里就把123转化成XYZ了
      

  5.   

    public class Example
    {
       public static void main(String[] args)
       {
         char i,j,k;
          for(i='x';i<='z';i++)
          for(j='x';j<='z';j++)
    {   
          if(i!=j)
               for(k='x';k<='z';k++)
          {
                   if(i!=k&&j!=k){
                           if(i!='x'&&k!='x'&&k!='z')
         System.out.println("order is a--"+i+"\tb--"+j+"\tc--"+k);
    }
    }
    }
    }这是我编的结果
    }
      

  6.   

    不是CSDN高手多吗?都在午睡吗?
      

  7.   

    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 
      

  8.   

    不是 这样的 ;
    不是两队 , 我看就是6个比    c说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单
      

  9.   

    a说他不和x比,c说他不和x,z比
    加上这个就不一样了
      

  10.   

    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] == "z"))))
                        continue label2;
                    else{
                        System.out.print(strArray1[i] +":"+ strArray2[j] +" ");
                        continue label1;
                    }                
                }
            }
    }
    不是C不和Y比是不和在比,改一下就对了
    这个程序变得很好
      

  11.   

    答案都可以看出来了..c说他不和x,z比  c VS y ,a说他不和x比 a VS z      so-> b VS x
      

  12.   

    刚刚我用屁股想了一个程序,是这样的
    System.out.print("a vs z,b vs x,c vs y");
      

  13.   

    我是刚学java,昨天老师教到第五章
    我是这样学的,直接从控制台输出
    System.out.println("a VS z");
    System.out.println("b VS x");
    System.out.println("c VS y");
    这样可以吗?
      

  14.   

    justinavril,你的程序貌似正确,不过仔细看条件的话“c说他不和x、z比”,而你的结果“c:z”明显不符合,就差一步!
      

  15.   

    每个程序都这样SUN公司十年前就关门了
      

  16.   

      if (((((strArray1[i] == "a") && (strArray2[j] == "x"))) ¦ ¦(((strArray1[i] == "c") && (strArray2[j] == "x")))) ¦ ¦(((strArray1[i] == "c") && (strArray2[j] == "Y"))))(((strArray1[i] == "c") && (strArray2[j] == "Y"))))这句的y改为z就对了 
      

  17.   

    我自己又琢磨了一个,可能比较长,但结果应该是对的:
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Iterator;
    /**
     * 
     * @author wych
     *
     */
    public class TestCal { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Player pa = new Player("a");
    Player pb = new Player("b");
    Player pc = new Player("c");
    Player px = new Player("x");
    Player py = new Player("y");
    Player pz = new Player("z");

    List jia = new ArrayList();
    jia.add(pa);
    jia.add(pb);
    jia.add(pc);
    List yi = new ArrayList();
    yi.add(px);
    yi.add(py);
    yi.add(pz);
    List newJia = new ArrayList();
    while(jia.size()>0){
    for(Iterator jiaIter = jia.iterator();jiaIter.hasNext();){
    Player jiaPlayer = (Player)jiaIter.next();
    l1:
    for(Iterator yiIter = yi.iterator();yiIter.hasNext();){
    Player yiPlayer = (Player)yiIter.next();
    if(unMatch(jiaPlayer.getName(),yiPlayer.getName())){
    System.out.println("####\n Sorry!" + jiaPlayer.getName() + " and " + yiPlayer.getName() + " can't match each other!");
    continue l1; 
    }else{
    boolean unMatchOther = false;
    List jia2 = jia.subList(0, jia.size());
    int jia2Size = jia2.size();
    for(int i=0;i<jia2Size;i++){
    Player jiaPlayer2 = (Player)jia2.get(i);
    if(jiaPlayer2 != jiaPlayer){
    if(unMatch(jiaPlayer2.getName(),yiPlayer.getName())||(jiaPlayer2.getFighterName()!=null&&!yiPlayer.getName().equals(jiaPlayer2.getFighterName()))){

    }else{
    unMatchOther = true;
    }
    }
    }
    if(!unMatchOther){
    System.out.println("####\n Congratulation!!Match!");
    jiaPlayer.setFighterName(yiPlayer.getName());
    yiPlayer.setFighterName(jiaPlayer.getName());
    newJia.add(jiaPlayer);
    jiaIter.remove();
    }else{
    System.out.println("####\n Sorry!" + jiaPlayer.getName() + " and " + yiPlayer.getName() + " can't match each other!");
    }
    }
    }
    }
    }
    for(int i=0;i<newJia.size();i++){
    Player player = (Player)newJia.get(i);
    System.out.println("####\n Player " + player.getName() + " vs Player " + player.getFighterName());
    }
    }


    public static boolean unMatch(String name1,String name2){
    boolean flag = false;
    if("a".equals(name1)&&"x".equals(name2)){
    flag = true;
    }
    if("c".equals(name1)&&"x".equals(name2)){
    flag = true;
    }
    if("c".equals(name1)&&"z".equals(name2)){
    flag = true;
    }
    return flag;
    }

    }class Player{

    private String name;

    private String fighterName;

    public String getName(){
    return name;
    }

    public void setFighterName(String _fighterName){
    fighterName = _fighterName;
    }
    public String getFighterName(){
    return fighterName;
    }

    public Player(String _name){
    name = _name;
    }
    }