//
// Created by Cauchyshy on 2023/5/3.
//
#include <bits/stdc++.h>
using namespace std;
// 策划 美术 研发
#define CEHUA 0
#define MEISHU 1
#define YANFA 2
class Worker {
public:
string name;
int salary;
};
void create_Worker(vector<Worker> &ve) {
string nameS = "ABCDEFGHIJ";
for (int i = 0; i < 10; ++i) {
Worker worker;
worker.name = "员工";
worker.name += nameS[i];
worker.salary = rand() % 10086 + 5000;
ve.push_back(worker);
}
}
void show_Worker(const vector<Worker> &workers) {
for (auto worker : workers) {
cout << "姓名: " << worker.name << " 工资: " << worker.salary << endl;
}
}
void set_Group(vector<Worker> &v, multimap<int, Worker> &m) {
for (auto &it : v) {
int depId = rand() % 3; // 部门编号
m.insert({depId, it});
}
}
void showWorkerByGroup(multimap<int, Worker> &m) {
cout << "策划部门: " << endl;
auto it = m.find(CEHUA);
int cnt = m.count(CEHUA);
int idx = 0;
for (; it != m.end() && idx < cnt; it++, idx++) {
cout << "姓名: " << it->second.name << " 工资: " << it->second.salary << endl;
}
cout << "--------------------------分割线--------------------------" << endl;
cout << "美术部门: " << endl;
it = m.find(MEISHU);
cnt = m.count(MEISHU);
idx = 0;
for (; it != m.end() && idx < cnt; it++, idx++) {
cout << "姓名: " << it->second.name << " 工资: " << it->second.salary << endl;
}
cout << "--------------------------分割线--------------------------" << endl;
cout << "研发部门: " << endl;
it = m.find(YANFA);
cnt = m.count(YANFA);
idx = 0;
for (; it != m.end() && idx < cnt; it++, idx++) {
cout << "姓名: " << it->second.name << " 工资: " << it->second.salary << endl;
}
}
void test() {
srand((unsigned int)time(NULL));
vector<Worker> workers;
create_Worker(workers);
// showWorker(workers);
multimap<int, Worker> mul_Workers;
set_Group(workers, mul_Workers);
showWorkerByGroup(mul_Workers);
}
int main() {
test();
return 0;
}
C++员工分组
最新推荐文章于 2024-11-04 23:11:51 发布