当前位置:网站首页>multimap案例
multimap案例
2022-07-27 14:23:00 【coder_Alger】
题目描述
- 公司今天招聘了5个员工,5名员工进入公司之后,需要指派员工在那个部门工作
- 人员信息有:姓名年龄电话工资等组成
- 通过multimap进行信息的插入保存显示
- 分部门显示员工信息显示全部员工信息
代码
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
#include <map>
using namespace std;
enum {RENLI,MEISHU,YANFA};
class Person
{
public:
Person(string name, int money):m_Name(name),m_money(money) {}
public:
string m_Name;
int m_money;
};
void createWorker(vector<Person> &v)
{
string nameSeed = "ABCDE";
for (int i = 0;i<5;i++)
{
string name = "员工";
name += nameSeed[i];
int money = rand() % 10001 + 10000;
Person p(name,money);
v.push_back(p);
}
}
void setGroup(vector<Person>&v,multimap<int,Person>&m)
{
for (vector<Person>::iterator it = v.begin();it != v.end();it++)
{
//随机产生部门编号
int departId = rand() % 3;
//将员工分到mutimap容器中
m.insert(make_pair(departId,*it));
}
}
void showGroup(multimap<int,Person>&m)
{
cout << "RENLI:" << endl;
multimap<int, Person>::iterator pos = m.find(RENLI);
int index = 0;
int num = m.count(RENLI);
for (;pos != m.end(),index<num;pos++,index++)
{
cout << "姓名:" << pos->second.m_Name << " " << "工资:" << pos->second.m_money << endl;
}
cout << "MEISHU:" << endl;
pos = m.find(MEISHU);
index = 0;
num = m.count(MEISHU);
for (; pos != m.end(), index < num; pos++, index++)
{
cout << "姓名:" << pos->second.m_Name << " " << "工资:" << pos->second.m_money << endl;
}
cout << "YANFA:" << endl;
pos = m.find(YANFA);
index = 0;
num = m.count(YANFA);
for (; pos != m.end(), index < num; pos++, index++)
{
cout << "姓名:" << pos->second.m_Name << " " << "工资:" << pos->second.m_money << endl;
}
}
int main()
{
//创建随机数种子
srand((unsigned int)time(NULL));
//创建5个员工
vector<Person>v;
createWorker(v);
//员工创建测试
/*for (vector<Person>::iterator it = v.begin(); it != v.end();it++)
{
cout << "name:" << it->m_Name << " " << "money:" << it->m_money << endl;
}*/
//设置分组,分组的multimap容器
multimap<int, Person>m;
setGroup(v,m);
//分部门显示员工
showGroup(m);
return 0;
}边栏推荐
- Code coverage statistical artifact -jacobo tool practice
- Record record record
- Network equipment hard core technology insider router Chapter 17 dpdk and its prequel (II)
- Watermelon book machine learning reading notes Chapter 1 Introduction
- 两阶段提交与三阶段提交
- 修改 Spark 支持远程访问OSS文件
- Principle of MOS tube to prevent reverse connection of power supply
- TCC
- Leetcode 191. number of 1 bits bit operation /easy
- Two stage submission and three stage submission
猜你喜欢

Leetcode 783. binary search tree node minimum distance tree /easy

Several basic uses of tl431-2.5v voltage reference chip

基于stm32的数字示波器设计方案

Huayun data creates a perfect information technology and innovation talent training system to help the high-quality development of information technology and innovation industry

积分运算电路的设计方法详细介绍

Digital storage oscilloscope based on FIFO idt7202-12

Code coverage statistical artifact -jacobo tool practice

3.3-5v conversion

DIY制作示波器的超详细教程:(一)我不是为了做一个示波器

Singles cup, web:web check in
随机推荐
EMC design scheme of CAN bus
Selenium 报错:session not created: This version of ChromeDriver only supports Chrome version 81
Unity 鼠标控制第一人称摄像机视角
仅做两项修改,苹果就让StyleGANv2获得了3D生成能力
STM32之CAN ---CAN ID过滤器分析
Leetcode 190. reverse binary bit operation /easy
DIY ultra detailed tutorial on making oscilloscope: (1) I'm not trying to make an oscilloscope
Unity mouse controls the first person camera perspective
Data warehouse project is never a technical project
Introduction to STM32 learning can controller
Network equipment hard core technology insider router Chapter 4 Jia Baoyu sleepwalking in Taixu Fantasy (Part 2)
The mobile terminal uses the list component of vantui. When multiple tab items are switched back and forth, the list is loaded many times, resulting in the failure of normal display of data
积分运算电路的设计方法详细介绍
谷粒商城配置CorsWebFilter后,报错:Resource sharing error:MultipleAllowOriginValues
STL value string learning
"Sword finger offer" linked list inversion
IJCAI 2022 outstanding papers were published, and 298 Chinese mainland authors won the first place in two items
Network equipment hard core technology insider router Chapter 16 dpdk and its prequel (I)
Sword finger offer merges two sorted linked lists
Transactions_ Basic demonstrations and transactions_ Default auto submit & manual submit