小红花STL

要求:幼儿园中按班组织学生,每个班学生按学号排号,规模为25个孩子,学校每天出勤用一个bitset描述,1代表出勤,0代表缺勤,试着编写接口函数,

输出每个孩子序号与出勤数

找出出勤率最高的3个孩子给当月的小红花。

数据:

1111111111111111111111111

1110111011101110111011100

1101101101101101101101101

1111011110111101111011110

0011101110111101111101111

0011101111011111110111111

1111101111110111111100111

1100111110001111111111110

1111111111111101111111111

1111011111011111111110111

 

#include
#include
#include
#include
#include
#include
#include
using namespace std;
template
class base
{
public:
	bitset b;
	int id;

};

template
class com
{
public:
	com() {}
	bool operator()(const base& b1, const base&b2)
	{
		return b1.b.count() <= b2.b.count() ? false : true;
	
	}
};


void main()
{
	vectorv;
	ifstream out("data.txt");
	copy(istream_iterator(out), istream_iterator(), back_inserter(v));
	vector> vb(25);
	cout << endl;
	cout << endl;	cout << endl;
	for (int i=0;i<25;i++)
	{
		for (int j =0;j<10;j++)
		{
			vb[i].b.set(j, (v[j * 25 + i]-48));
		}
		vb[i].id = i;
		cout << vb[i].b.to_string() << endl;
	}
	for (int i=0;i<25;i++)
	{
		cout << vb[i].b.count() << endl;
	}
	sort(vb.begin(),vb.end(),com<10>());
	for (int i = 0; i < 25; i++)
	{
		cout << vb[i].b.to_string() <<"   "<

测试结果:

小红花STL_第1张图片

 

你可能感兴趣的:(小红花STL)