#include <iostream>
using namespace std;
class Student{
char _theMan;
bool _isEqual;
public:
Student(bool isEqual, char theMan): _isEqual(isEqual), _theMan(theMan){ }
bool operator() (char thisMan);
};
bool Student::operator() (char thisMan){
return _isEqual ? (thisMan == _theMan) : (thisMan != _theMan);
}
char solve(int number, int correct, Student* student){
for(int i = 0; i < number; i++){
int count = 0;
char thisMan = 'A' + i;
for(int j = 0; j < number; j++)
count += student[j](thisMan);
if(count == correct)
return thisMan;
}
return '\0';
}
int main(){
Student student[] = {Student(false, 'A'), Student(true, 'C'),
Student(true, 'D'), Student(false, 'D')};
char theMan = solve(4, 3, student);
if(theMan != '\0'){
cout << "It is " << theMan << endl;
}
else{
cout << "No solve." << endl;
}
return 0;
}
MOOC清华《面向对象程序设计》第5章:OOP版谁做的好事
最新推荐文章于 2021-05-22 02:35:39 发布