C++入门必做题(第二题)

来源:互联网 发布:数据做预测的方法 编辑:程序博客网 时间:2024/06/05 14:32

2. A、B、C、D、E五名学生有可能参加计算机竞赛,根据下列条件判断哪些
人参加了竞赛:

(1)A参加时,B也参加;

(2)B和C只有一个人参加;

(3)C和D或者都参加,或者都不参加;

(4)D和E中至少有一个人参加;

(5)如果E参加,那么A和D也都参加。

 // 入门必做题2.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
using namespace std;
void mine(const int&a,const int&b,const int&c,const int&d,const int&e)
{
cout<<"去参加的人为"<<endl;
if (a==1)
{
cout<<"a"<<endl;
}
if (b==1)
{
cout<<"b"<<endl;
}
if (c==1)
{
cout<<"c"<<endl;
}
if (d==1)
{
cout<<"d"<<endl;
}
if (e==1)
{
cout<<"e"<<endl;
}
}

int main()
{
int a,b,c,d,e;
for(a=0;a<2;a++)
{
for(b=0;b<2;b++)
{
for(c=0;c<2;c++)
{
for(d=0;d<2;d++)
{
for(e=0;e<2;e++)
{
if ((a==1&&b==1)||a==0)
{

if (b!=c)
{
if (c==d)
{
if (!(d==0&&e==0))
{
if ((e==1&&a==1&&d==1)||e==0)
{
mine(a,b,c,d,e);
}
}
}
}
}

}
}
}
}
}
return 0;
}

原创粉丝点击