当前位置:网站首页>小红花STL
小红花STL
2022-07-28 05:30:00 【▀】
要求:幼儿园中按班组织学生,每个班学生按学号排号,规模为25个孩子,学校每天出勤用一个bitset描述,1代表出勤,0代表缺勤,试着编写接口函数,
输出每个孩子序号与出勤数
找出出勤率最高的3个孩子给当月的小红花。
数据:
1111111111111111111111111 1110111011101110111011100 1101101101101101101101101 1111011110111101111011110 0011101110111101111101111 0011101111011111110111111 1111101111110111111100111 1100111110001111111111110 1111111111111101111111111 1111011111011111111110111 |
#include<iostream>
#include<vector>
#include<bitset>
#include<algorithm>
#include<fstream>
#include<string>
#include<iterator>
using namespace std;
template<size_t N>
class base
{
public:
bitset<N> b;
int id;
};
template<size_t N>
class com
{
public:
com() {}
bool operator()(const base<N>& b1, const base<N>&b2)
{
return b1.b.count() <= b2.b.count() ? false : true;
}
};
void main()
{
vector<char>v;
ifstream out("data.txt");
copy(istream_iterator<char>(out), istream_iterator<char>(), back_inserter(v));
vector<base<10>> 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() <<" "<<vb[i].id<< endl;
}
cout << "小红花的同学是" << endl;
cout << vb[0].id <<" "<< vb[1].id << " " << vb[2].id << " " <<vb[3].id<<endl;
cin.get();
}测试结果:

边栏推荐
猜你喜欢

Basic knowledge of functions and special points

DOM -- event chain, event bubble and capture, event proxy

Shell--- function

Event_ Loop event loop mechanism

一个定时任务提醒工具

MOOC Weng Kai C language fourth week: further judgment and circulation: 1. Logical types and operations 2. Judgment of cascading and nesting

远程访问云服务器上Neo4j等服务的本地网址

根据excel生成create建表SQL语句

Starting point Chinese website font anti crawling technology web page can display numbers and letters, and the web page code is garbled or blank

Results fill in the blank shopping list (teach you to solve it with Excel)
随机推荐
Shell--- sed statement exercise
Freemaker exports word with tables and multiple pictures to solve the repetition and deformation of pictures
NAT network address translation
DOM -- page rendering, style attribute operation, preloading and lazy loading, anti shake and throttling
Open virtual machine kali2022.2 and install GVM
Construction of Yum warehouse
Shell --- conditional statement practice
Branch and loop statements
Review of C language (variable parameters)
Method of decomposing path into directory name and file name
Insert sort of sort
C language push box
Uni app double click event simulation
Basic knowledge of functions and special points
easypoi导出表格带echars图表
DOM - Events
Standard C language learning summary 3
Standard C language summary 2
New, let, VaR, const and temporary deadband. The difference between XML and JSON
Softmax multi classification gradient derivation