#include <iostream>
#include <fstream>
#include <vector>
#include <bitset>
#include <sstream>
#include <string>
#include <algorithm>
using namespace std;
class Child
{
public:
int id;
int attendDay;
void setId(int id){this->id=id;}
void setAttendDay(){this->attendDay=0;}
int getId(){return id;}
int getAttendDay(){return attendDay;}
};
class show
{
vector<Child> &v;
public:
show(vector<Child>& l):v(l){}
void operator()(bitset<25> &b)
{
int i=0;
for (int j=0;j<25;j++)
{
if (b.test(j)==1)
{
v[j].attendDay++;
}
}
}
};
int main()
{
vector<Child>vec_c;
vector<bitset<25>>vec_b;
char str[26];
ifstream in("E:\\onduty.txt");
if(!in)
{
cout<<"输入流输入错误"<<endl;
return 0;
}
for (int i=0;i<25;i++)
{
Child c;
c.setId(i);
c.setAttendDay();
vec_c.push_back(c);
}
while (in.getline(str,26))
{
bitset<25>b(str);
vec_b.push_back(b);
}
for_each(vec_b.begin(),vec_b.end(),show(vec_c));
/* for (int i=0;i<vec_b.size();i++)
{
for (int j=0;j<vec_c.size();j++)
{
if (vec_b[i].test(j)==1)
{
vec_c[j].attendDay++;
}
}
}
for (int i=0;i<vec_c.size();i++)
{
cout<<"学生学号"<<25-vec_c[i].id<<" "<<"该学生出勤天数"<<vec_c[i].attendDay<<endl;
}
in.close();
system("pause");
return 0;
}
小红花问题(C++)
最新推荐文章于 2021-12-15 21:51:15 发布