67,513
社区成员
发帖
与我相关
我的任务
分享
【程序18】
题目:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。
已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。
public static void select(char[] buf, int start, int end, char[] buf0) {
if (start == end) {
for (int i = 0; i <= end; i++) {
if (buf[0] != 'x' && buf[2] != 'x' && buf[2] != 'z')
System.out.print(buf[i]);
}
} else {
for (int i = start; i <= end; i++) {
char temp = buf[start];
buf[start] = buf[i];
buf[i] = temp;
select(buf, start + 1, end, buf0);
temp = buf[start];
buf[start] = buf[i];
buf[i] = temp;
}
}
}
public static void main(String[] args) {
char buf1[] = { 'a', 'b', 'c' };
char buf2[] = { 'x', 'y', 'z' };
select(buf2, 0, buf2.length - 1, buf1);
}