栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【C++】员工排序,vector、multimap

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【C++】员工排序,vector、multimap

#include
using namespace std;
#include"list"
#include
#include"vector"
#include"string.h"
#include"map"
#include"ctime"
#define CEHUA 0 
#define MEISHU 1 
#define YANFA 2

class Worker {
public:
	string m_name;
	int m_salary;
};


void creatworker(vector& v) {
	string nameseed = "ABCDE";
	for (int i = 0; i < 5; i++) {
		Worker worker;
		worker.m_name = "员工";
		worker.m_name += nameseed[i];
		worker.m_salary = rand() % 10000 + 10000;
		
		v.push_back(worker);
	}

}

void setgroup(vector& v,multimap& m) {
	for (vector::iterator it = v.begin(); it != v.end(); it++) {
		int depid = rand() % 3;
		m.insert(make_pair(depid, *it));

	}

}

void printgroup(multimap& m) {
	cout << "策划部门:" << endl;

	multimap::iterator pos = m.find(CEHUA);
	int  count = m.count(CEHUA);
	for (int index = 0;pos!=m.end()&&index 
		cout << pos->second.m_name << " " << pos->second.m_salary;
	}
	cout << endl;



	cout << "美术部门:" << endl;

	 pos = m.find(MEISHU);
	int  count2 = m.count(MEISHU);
	for (int index = 0; pos != m.end() && index < count2; pos++,index++) {
		cout << pos->second.m_name << " " << pos->second.m_salary;
	}
	cout << endl;


	cout << "研发部门:" << endl;

	 pos = m.find(YANFA);
	int  count3 = m.count(YANFA);
	for (int index = 0; pos != m.end() && index < count3; pos++,index++) {
		cout << pos->second.m_name << " " << pos->second.m_salary;
	}
	cout << endl;

}

int main() 
{
	srand((unsigned)time(NULL));
	vectorvworker;
	creatworker(vworker);
	
	for (vector::iterator it = vworker.begin(); it != vworker.end(); it++) {
		cout << "姓名" << it->m_name << " " << it->m_salary << " " << endl;
	}
	
	multimapmworker;
	setgroup(vworker, mworker);

	printgroup(mworker);
	system("pause");
	return 0;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/938538.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号