Problem Description: Three couples the wedding, the groom three A, B, C, three brides X, Y, Z. Some people want to know who and whom to marry, so he asked them: A said he would marry and X; X said her fiance is C; C and Z said he would marry. They are lying. Programming who seek and whom to marry.
ALGORITHM: Construction logical expression (a = 1 && c = 1 && c = 3 && a = b && b = c && a = c!!!!!!)
Note that character output
Own algorithms have a little problem, not output characters
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c;
for(a=1;a<=3;a++)
for(b=1;b<=3;b++)
for(c=1;c<=3;c++)
{
if(a!=1 && c!=1 && c!=3 && a!=b && b!=c && a!=c)
{
printf("A与%d结婚\n",a);
printf("B与%d结婚\n",b);
printf("C与%d结婚\n",c);
}
}
return 0;
}
The output is:
standard answer can output characters:
#include<stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c; //a,b,c为三个男人
for(a=1;a<=3;a++) //给a,即第一个男人尝试匹配给每一个女人
for(b=1;b<=3;b++) //给a,即第一个男人尝试匹配给每一个女人
for(c=1;c<=3;c++) //给a,即第一个男人尝试匹配给每一个女人
if(a!=1 && c!=3 && c!=1 && a!=b && b!=c && a!=c) //根据他们说的话进行判断
{
//符合条件,即正确的情况下,输出正确答案
printf("%c将嫁给A\n",'X'+a-1);
printf("%c将嫁给B\n",'X'+b-1);
printf("%c将嫁给C\n",'X'+c-1);
printf("\n");
printf("%d将嫁给A\n",a);
printf("%d将嫁给B\n",b);
printf("%d将嫁给C\n",c);
}
//程序计算结束。退出程序
system("pause");
return 0;
}
The results are: