c++逻辑判断问题

来源:百度知道 编辑:UC知道 时间:2024/05/29 21:01:47
题目是这样的:
5家空调厂进行质量评比。评比之前已经知道E厂肯定不是第2和第3.
A厂猜测:E厂第1.
B厂猜测:B厂第2.
C厂猜测:A厂最差。
D厂猜测:C厂不是最好。
E厂猜测:D厂第1.
评比结果出来后发现,只有获得第1和第2的两个厂商猜对了。编程判断各个厂的名次。

我编的程序如下:
#include<iostream>
using namespace std;
int main()
{
int a,b,c,d,e,as,bs,cs,ds,es;

for(a=2;a<=5;a++)
for(b=2;b<=5;b++)
for(c=1;c<5;c++)
for(d=1;d<=5;d++)
for(e=1;e<=5;e++)
{ as=(e==1);bs=(b==2);cs=(a==5);ds=(c!=1);es=(d==1);
if(e!=2&&e!=3&&
a!=b&&a!=c&&a!=d&&a!=e&&
b!=c&&b!=d&&b!=e&&
c!=d&&c!=e&&
d!=e &&
as+bs+cs+ds+es==2 )
{ cout<<"ABCDE各个厂的排名依次为"; cout<<a<<b<<c<<d<<e; }
}

return 0;
}
请高手帮忙看看哪里出了问题,或者说您给一个更好的方法。谢了!!!!!

#include <iostream>
#include <cmath>
#include <conio.h>

using namespace std;

bool checkA(int item[])
{
if (item[4] == 0)
return true;
return false;
}

bool checkB( int item[])
{
if(item[1] == 1)
return true;
return false;
}

bool checkC(int item[])
{
if(item[0] == 4)
return true;
return false;
}

bool checkD(int item[])
{
if(item[2] != 0)
return true;
return false;
}

bool checkE(int item[])
{
if(item[3] == 0)
return true;
return false;
}

int main()
{
int iAsr[5] = {0};
int counter;

for(counter = 0; counter < pow(5.0, 5.0); counter++)
{
bool flag = true;

iAsr[0] = counter % 5;
iAsr