当前位置: 代码迷 >> 综合 >> 找出三对赛手的名单
  详细解决方案

找出三对赛手的名单

热度:47   发布时间:2024-02-27 10:56:28.0

两个兵乓球队进行比赛,各出三人,甲队为a,b,c三人,乙队为x,y,z三人,已抽签决定比赛名单,有人向队员打听比赛的名单,a说他不和x比,c说他不和x,z比,请编程找出三对赛手的名单。 

#include<stdio.h>
#define Ax 5
#define Ay 6
#define Az 7
#define Bx 5
#define By 6
#define Bz 7
#define Cx 5
#define Cy 6
#define Cz 7
/*2020-10-11说明:team[][],第一个为小组,0 = 甲队 ,1 = 乙队第二个参数为某一队员的参数,[0][0]=a,[0][1]=b,[0][2]=c第二个参数的值为,取int的后三位做值,倒数一二位为匹配对象,01为x,10为y,11为z(2进制计数法)倒数第三位为匹配标识符,好像可以不需要,默认为1所以Ax =4+1 =5
*/
void main() {int team[1][3];int i, j, k;i = j = k = 5;while (1){//匹配Afor (;; i++){team[0][0] = i;if (j > 7)j = 5;if (team[0][0] != 5 && team[0][0] != team[0][1] && team[0][0] != team[0][2])break;}//匹配Bfor (;; j++){team[0][1] = j;if (j > 7)j = 5;if (team[0][1] != team[0][0] && team[0][1] != team[0][2])break;}//匹配Cfor (;; k++){team[0][2] = k;if (k > 7)k = 5;if (team[0][2] != 5 && team[0][2] != 7)break;}if (team[0][0] > 4 && team[0][1] > 4 && team[0][1] > 4)  //每一位都超过4,表面都匹配上了if (team[0][0] != team[0][1] && team[0][0] != team[0][2] && team[0][1] != team[0][2])if (team[0][0] != Ax && team[0][2] != Cx && team[0][2] != Cz)break;//满足退出}switch (team[0][0]){case 5: printf("A与x匹配\n"); break;case 6: printf("A与y匹配\n"); break;case 7: printf("A与z匹配\n"); break;}switch (team[0][1]){case 5: printf("B与x匹配\n"); break;case 6: printf("B与y匹配\n"); break;case 7: printf("B与z匹配\n"); break;}switch (team[0][2]){case 5: printf("C与x匹配\n"); break;case 6: printf("C与y匹配\n"); break;case 7: printf("C与z匹配\n"); break;}
}

 

  相关解决方案