清华附中有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;
}