MOOC清华《程序设计基础》第3章:谁做的好事(顺序枚举)

来源:互联网 发布:无线电接收软件 编辑:程序博客网 时间:2024/06/05 11:18

清华附中有ABCD四位同学,在某一天一起值日。放学路上扶起了摔倒的老奶奶。老奶奶给清华附中送来了表扬信,校长很想知道他们四个人中谁做了好事。

A说:不是我。B:是C。C:是D。D:他胡说。已知三人说了真话一人说了假话,请问谁做的好事?


#include <iostream>using namespace std;int main(){char good_man;good_man = 'A';int count = 0;if(good_man != 'A')count++;if(good_man == 'C')count++;if(good_man == 'D')count++;if(good_man != 'D')count++;if(count == 3)cout << good_man << endl;else {good_man = 'B';int count = 0;if(good_man != 'A')count++;if(good_man == 'C')count++;if(good_man == 'D')count++;if(good_man != 'D')count++;if(count == 3)cout << good_man << endl;else{good_man = 'C';int count = 0;if(good_man != 'A')count++;if(good_man == 'C')count++;if(good_man == 'D')count++;if(good_man != 'D')count++;if(count == 3)cout << good_man << endl;else{good_man = 'D';int count = 0;if(good_man != 'A')count++;if(good_man == 'C')count++;if(good_man == 'D')count++;if(good_man != 'D')count++;if(count == 3)cout << good_man << endl;}}}return 0;}


阅读全文
0 0
原创粉丝点击