任务4.1 谁做的好事
清华附中有4位同学中的一位做了好事不留名。表扬信来了之后,校长问这4位是谁做的好事。
A说:不是我。
B说:是C。
C说:是D。
D说:他胡说。
已知3个人说的是真话,一个人说的是假话。现在要根据这些信息,找出做了好事的人。
//************************************************
//* Source Name: ChapterFour_JobOne.cpp
//* Founction : Who does good deed
//* Author : Skyera
//* Create Time : 2025-7-17
//* Modify :
//* Modify Time:
//************************************************
#include <iostream>
using namespace std;
int main()
{char thisman;int sum = 0, k;for(k=0; k<4; k++){thisman = k + 'A';sum = (thisman != 'A')+ (thisman == 'C')+ (thisman == 'D')+ (thisman != 'D');if(sum == 3){cout << "做好事的人是:" << thisman << endl;return 0;}}cout << "无法确定是谁做的好事。" << endl;return 1;
}