MOOC清华《面向对象程序设计》第5章:OOP版谁做的好事
来源:互联网 发布:linux文件目录绿色标 编辑:程序博客网 时间:2024/06/05 14:23
#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;}
阅读全文
0 0
- MOOC清华《面向对象程序设计》第5章:OOP版谁做的好事
- MOOC清华《面向对象程序设计》第5章:OOP版电子计价器
- MOOC清华《面向对象程序设计》第5章:OOP版填充数字旋转矩阵
- MOOC清华《面向对象程序设计》第5章:OOP版填充数字旋转矩阵-产品级!-终极中文版!
- MOOC清华《面向对象程序设计》第5章:OOP版填充数字矩阵(采用模板方法)
- MOOC清华《面向对象程序设计》第9章:听课感想
- MOOC清华《面向对象程序设计》第5章:OOP版填充数字矩阵-产品级终极中文版 v 2.0(增加按行、按列填充)
- MOOC清华《程序设计基础》第3章:谁做的好事(顺序枚举)
- MOOC清华《程序设计基础》第3章:谁做的好事(循环枚举)
- MOOC清华《面向对象程序设计》第2章:基于范围的for循环实验
- MOOC清华《面向对象程序设计》第2章:函数参数的缺省值实验
- MOOC清华《面向对象程序设计》第2章:类class的综合实验
- MOOC清华《面向对象程序设计》第4章:函数模板的特化实验
- MOOC清华《面向对象程序设计》第4章:类模板的特化实验
- MOOC清华《面向对象程序设计》第6章:负载监视器的设计
- MOOC清华《面向对象程序设计》第8章:栈的实现(基于数组)
- MOOC清华《面向对象程序设计》第8章:栈的实现(基于STL vector)
- MOOC清华《面向对象程序设计》第8章:栈的实现(采用适配器模式)
- 【verilog语法】modelsim编译verilog代码报Error:range must be bounded by constant expressions
- 基于FPGA PLL锁相环实现及示波器波形失真分析
- Windows 安装 curl
- FLASK-SQLALchemy 的介绍与安装
- Matlab以MEX方式调用C源代码
- MOOC清华《面向对象程序设计》第5章:OOP版谁做的好事
- setContentVIew学习
- Day60-Oracle04
- 设计模式C++版:第二十一式观察者模式
- Linux nohup命令分析
- 引用和指针有什么区别,汇编分析(最真实)
- 发布上线前,先小秀一把俺的64位浏览器,速度那觉对是杠杠滴,上youtube,上google不费劲
- Potplayer制作视频缩略图的方法
- Java接口