对手是谁?

题目:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单:
a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。
//定义两个集合,里面是两只队伍
ArrayList<String> teamA = new ArrayList<String>();
teamA.add("a");
teamA.add("b");
teamA.add("c");
ArrayList<String> teamB = new ArrayList<String>();
teamB.add("x");
teamB.add("y");
teamB.add("z");

//筛选条件 
String temp1 = "x";
String temp2 = "x";
String temp3 = "z";

//tempA 代表a的对手列表
ArrayList<String> tempA = teamB.remove("x");
teamB.add("x");

//tempC 代表c的对手列表
teamB.remove("x");
teamB.remove("z");
ArrayList<String> tempC = teamB;
teamB.add("x");
teamB.add("z");

//teamC里面就是c的对手了
String c = tempC .get(0);
//从teamA的里面把c的对手排除掉,剩下的就是a的对手了
String a = tempA.remove(c).get(0);
//从teamB中排除掉a和c的对手,剩下的就是b的对手了
teamB.remove(a);
teamB.remove(c);
String b = teamB.get(0);
System.out.println("c : " + c);
System.out.println("a : " + a);
System.out.println("b : " + b);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值