4名专家对4款赛车进行评论。
A说:2号赛车是最好的。
B说:4号赛车是最好的。
C说:3号赛车不是最好的。
D说:B说错了。
事实上只有一款赛车最佳,且只有一名专家说对了,其他3人都说错了。请编程输出最佳车的车号,以及哪位专家说对了。
程序如下:
include
using namespace std;
int main(){
int answer;
int thisCar;
for(thisCar=1;thisCar<5;thisCar++){
answer=(thisCar==2)+(thisCar==4)+(thisCar!=3)+(thisCar!=4);
if(answer==1){
cout<<"最佳赛车是"<<thisCar<<"号!"<<endl;
if(thisCar==1){
cout<<"D专家说对了。"<<endl;
}
if(thisCar==2){
cout<<"A专家说对了。"<<endl;
}
if(thisCar==3){
cout<<"D专家说对了。"<<endl;
}
if(thisCar==4){
cout<<"B专家说对了。"<<endl;
}
}
}
return 0;
}