题目:两个乒乓球队进行比赛,各出三人。甲队为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)