java乒乓球比赛问题_[导入]程序十八:很经典的乒乓球问题:

【程序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 - java , 乒乓球问题

文章来源:http://www.tt-shopping.com/kevinlau/read.php/94.htm

posted on 2009-05-05 22:09 蓝冰飞寒 阅读(47) 评论(0)  编辑  收藏

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值