语源科技BlogJava 联系 聚合 管理  

Blog Stats

News

 

蓝冰飞寒个人独立博客地址,www.uphenan.com

随笔档案

文章档案


蓝冰飞寒

用心去做每一件事情

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

class Ping
{
public boolean bool ;
public String name;
public Ping(String name)
{
  bool = true;
  this.name = name;
}
}
public class Test1
{
public static void main(String args[])
{
  
  Ping team1[] = new Ping[3];
  Ping team2[] = new Ping[3];
  Ping a = new Ping("a");
  team1[0] = a;
  Ping b = new Ping("b");
  team1[1] = b;
  Ping c = new Ping("c");
  team1[2] = c;
  
  Ping x = new Ping("x");
  team2[0] = x;
  Ping y = new Ping("y");
  team2[1] = y;
  Ping z = new Ping("z");
  team2[2] = z;
  String c1 = "";
//c 不对 x,z  a 不对 x
  for(int i = 0;i < team1.length;i++){
   for(int j = 0;j < team2.length;j++){
    if(team1[i].name == "c" && team1[i].bool){
     if(team2[j].name == "x" || team2[j].name == "z"){
      continue;
     }else{
      team1[i].bool = false;
      team2[j].bool = false;
      c1 = team1[i].name;
      if(!team1[i].bool && !team2[j].bool){
       System.out.println(team1[i].name+" VS "+team2[j].name);
      }
      i = 0;
     }
    }else if(team1[i].bool && c1 != ""){
     if(team1[i].name == "a" && team2[j].name == "x"){
      continue;
     }else if(team1[i].name == "a" && team2[j].name != "x" && team2[j].bool){
      team1[i].bool = false;
      team2[j].bool = false;
     }else{
      team1[i].bool = false;
      team2[j].bool = false;
     }
     if(!team1[i].bool && !team2[j].bool){
      System.out.println(team1[i].name+" VS "+team2[j].name);
     }
    }
   }
  }
}
}
Tags - ,
文章来源:http://www.tt-shopping.com/kevinlau/read.php/94.htm
posted on 2009-05-05 22:09 蓝冰飞寒 阅读(100) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: