20240511, STL案例2-员工分组

拜托铠甲勇士真的帅好不好!!!

 STL案例2-员工分组

10个员工,指派部门,员工信息(姓名,工资组成,部门:策划,美术,研发),随机分配部门和公司,MULTIMAP插入信息,KEY部门编号,VAL员工,分部门显示员工信息

#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<ctime>
using namespace std;
#define CEHUA 0
#define SHEJI 1
#define KAFA 2

class Worker {
public:
	Worker(string name, int salary) {
		this->_name = name;
		this->_sal = salary;
	}
public:
	string _name;
	int _sal;
};
void creatww(vector<Worker>& w) {
	srand((unsigned int)time(NULL));
	string nameseed = "ABCDEFGHIJ";
	for (int i = 0; i < 10; i++) {
		string name = "员工-";
		name += nameseed[i];
		int sal=rand() % 6001 + 7000;
		Worker p(name, sal);
		w.push_back(p);
	}
}
void setgroup(vector<Worker> w,multimap<int, Worker> &mw) {
	for (vector<Worker>::iterator it = w.begin(); it != w.end(); it++) {
		//产生随机部门编号
		int depid = rand() % 3;
		mw.insert(make_pair(depid, *it));
	}
}
void showgroup(multimap<int,Worker>&mw) {
	cout << endl;
	cout << "group CEHUA:\t" << endl;
	multimap<int, Worker>::iterator pos = mw.find(CEHUA);
	int count = mw.count(CEHUA);//统计具体人数
	int index = 0;
	for (; pos != mw.end() && index < count; pos++, index++) {//pos->first!=CEHUA不对脑子清醒了再试
		cout << pos->second._name << " " << pos->second._sal << endl;
	}
	cout << endl;
	cout << "group SHEJI:\t" << endl;
	pos = mw.find(SHEJI);
	count = mw.count(SHEJI);//统计具体人数
	index = 0;
	for (; pos != mw.end() && index < count; pos++, index++) {
		cout << pos->second._name << " " << pos->second._sal << endl;
	}
	cout << endl;
	cout << "group KAFA:\t" << pos->first << endl;
	pos = mw.find(KAFA);
	count = mw.count(KAFA);//统计具体人数
	index = 0;
	for (; pos != mw.end() && index < count; pos++, index++) {
		cout << pos->second._name << " " << pos->second._sal << endl;
	}
}
void tst01() {
	vector<Worker>w;
	creatww(w);
	for (vector<Worker>::iterator it = w.begin(); it != w.end(); it++) {
		cout << it->_name << " " << it->_sal << endl;
	}
	cout << endl;
	multimap<int, Worker>mw;
	setgroup(w,mw);
	showgroup(mw);
}
int main() {
	tst01();
	system("pause");
	return 0;
}

  • 10
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值