Используйте bitset для хранения информации о том, кто в текущий день присутствует на занятиях. Прочтите эти bitset за 12 дней и определите кто присутствовал всегда? Кто присутствовал не менее 8 дней.?
Мы создали вектор из bitset<12>, 12 это дней. Сразу примерчик без комментариев.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#include <iostream> using std::cout; using std::endl; #include <bitset> using std::bitset; #include <iomanip> using std::setw; #include <cstdlib> using std::exit; using std::rand; using std::srand; #include <vector> using std::vector; int main() { vector<bitset<12> > v(20); for(int i=0;i<20;++i) { for(int j=0;j<12;++j) { v[i][j]=rand()%2; } } int count(0); for(int i=0;i<20;++i) { if(v[i].count()>=8) count++; cout <<v[i]<<endl; } cout <<"count= "<<count<<endl; return 0; } |
[youtube]http://www.youtube.com/watch?v=UxF7GLd8QcA[/youtube]