两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。用c++实现
时间: 2023-05-29 20:05:51 浏览: 98
经典C语言程序100例2
#include <iostream>
using namespace std;
int main() {
char a, b, c, x, y, z;
for(a = 'x'; a <= 'z'; a++) {
for(b = 'x'; b <= 'z'; b++) {
if(a == b) continue; // a和b不能相同
for(c = 'x'; c <= 'z'; c++) {
if(a == c || b == c) continue; // a、b和c不能相同
x = 'x'; y = 'y'; z = 'z';
if(a == 'x' || c == 'x' || c == 'z') continue; // 根据题目要求判断
if(b == 'y' || c == 'y') continue;
if(a != 'z' && b != 'z' && y != 'z') continue; // x、y、z每个人都要参加比赛
cout << "甲队:" << a << " " << b << " " << c << endl;
cout << "乙队:" << x << " " << y << " " << z << endl;
}
}
}
return 0;
}
阅读全文