C+---map、multimapの使用
43196 ワード
map<T1, T2> mapTT;//map :
map(const map &mp);//
map& operator=(const map &mp);//
swap(mp);//
size();//
empty();//
map.insert(...); // , pair
map mapStu;
// pair
mapStu.insert(pair(3, " "));
// pair
mapStu.inset(make_pair(-1, " "));
// value_type
mapStu.insert(map::value_type(1, " "));
//
mapStu[3] = " ";
mapStu[5] = " ";
clear();//
erase(pos);// pos , 。
erase(beg,end);// [beg,end) , 。
erase(keyElem);// key keyElem 。
find(key);// key , , ;/ , map.end();
count(keyElem);// key keyElem 。 map , 0, 1。 multimap , 1。
lower_bound(keyElem);// key>=keyElem 。
upper_bound(keyElem);// key>keyElem 。
equal_range(keyElem);// key keyElem 。
ケース
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
using namespace std;
//multimap
// 5 ,5 ,
// :
// Multimap
//
#define SALE_DEPATMENT 1 //
#define DEVELOP_DEPATMENT 2 //
#define FINACIAL_DEPATMENT 3 //
#define ALL_DEPATMENT 4 //
//
class person{
public:
string name; //
int age; //
double salary; //
string tele; //
};
// 5
void CreatePerson(vector<person>& vlist){
string seed = "ABCDE";
for (int i = 0; i < 5; i++){
person p;
p.name = " ";
p.name += seed[i];
p.age = rand() % 30 + 20;
p.salary = rand() % 20000 + 10000;
p.tele = "010-8888888";
vlist.push_back(p);
}
}
//5
void PersonByGroup(vector<person>& vlist, multimap<int, person>& plist){
int operate = -1; //
for (vector<person>::iterator it = vlist.begin(); it != vlist.end(); it++){
cout << " :" << endl;
cout << " :" << it->name << " :" << it->age << " :" << it->salary << " :" << it->tele << endl;
cout << " (1 , 2 , 3 ):" << endl;
scanf("%d", &operate);
while (true){
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
using namespace std;
//multimap
// 5 ,5 ,
// :
// Multimap
//
#define SALE_DEPATMENT 1 //
#define DEVELOP_DEPATMENT 2 //
#define FINACIAL_DEPATMENT 3 //
#define ALL_DEPATMENT 4 //
//
class person{
public:
string name; //
int age; //
double salary; //
string tele; //
};
// 5
void CreatePerson(vector<person>& vlist){
string seed = "ABCDE";
for (int i = 0; i < 5; i++){
person p;
p.name = " ";
p.name += seed[i];
p.age = rand() % 30 + 20;
p.salary = rand() % 20000 + 10000;
p.tele = "010-8888888";
vlist.push_back(p);
}
}
//5
void PersonByGroup(vector<person>& vlist, multimap<int, person>& plist){
int operate = -1; //
for (vector<person>::iterator it = vlist.begin(); it != vlist.end(); it++){
cout << " :" << endl;
cout << " :" << it->name << " :" << it->age << " :" << it->salary << " :" << it->tele << endl;
cout << " (1 , 2 , 3 ):" << endl;
scanf("%d", &operate);
while (true){
if (operate == SALE_DEPATMENT){ //
plist.insert(make_pair(SALE_DEPATMENT, *it));
break;
}
else if (operate == DEVELOP_DEPATMENT){
plist.insert(make_pair(DEVELOP_DEPATMENT, *it));
break;
}
else if (operate == FINACIAL_DEPATMENT){
plist.insert(make_pair(FINACIAL_DEPATMENT, *it));
break;
}
else{
cout << " , (1 , 2 , 3 ):" << endl;
scanf("%d", &operate);
}
}
}
cout << " !" << endl;
cout << "***********************************************************" << endl;
}
//
void printList(multimap<int, person>& plist, int myoperate){
if (myoperate == ALL_DEPATMENT){
for (multimap<int, person>::iterator it = plist.begin(); it != plist.end(); it++){
cout << " :" << it->second.name << " :" << it->second.age << " :" << it->second.salary << " :" << it->second.tele << endl;
}
return;
}
multimap<int, person>::iterator it = plist.find(myoperate);
int depatCount = plist.count(myoperate);
int num = 0;
if (it != plist.end()){
while (it != plist.end() && num < depatCount){
cout << " :" << it->second.name << " :" << it->second.age << " :" << it->second.salary << " :" << it->second.tele << endl;
it++;
num++;
}
}
}
//
void ShowPersonList(multimap<int, person>& plist, int myoperate){
switch (myoperate)
{
case SALE_DEPATMENT:
printList(plist, SALE_DEPATMENT);
break;
case DEVELOP_DEPATMENT:
printList(plist, DEVELOP_DEPATMENT);
break;
case FINACIAL_DEPATMENT:
printList(plist, FINACIAL_DEPATMENT);
break;
case ALL_DEPATMENT:
printList(plist, ALL_DEPATMENT);
break;
}
}
//
void PersonMenue(multimap<int, person>& plist){
int flag = -1;
int isexit = 0;
while (true){
cout << " ((1 , 2 , 3 , 4 , 0 ):" << endl;
scanf("%d", &flag);
switch (flag)
{
case SALE_DEPATMENT:
ShowPersonList(plist, SALE_DEPATMENT);
break;
case DEVELOP_DEPATMENT:
ShowPersonList(plist, DEVELOP_DEPATMENT);
break;
case FINACIAL_DEPATMENT:
ShowPersonList(plist, FINACIAL_DEPATMENT);
break;
case ALL_DEPATMENT:
ShowPersonList(plist, ALL_DEPATMENT);
break;
case 0:
isexit = 1;
break;
default:
cout << " , !" << endl;
break;
}
if (isexit == 1){
break;
}
}
}
int main(){
vector<person> vlist; // 5
multimap<int, person> plist; //
// 5
CreatePerson(vlist);
//5
PersonByGroup(vlist, plist);
//
PersonMenue(plist);
system("pause");
return EXIT_SUCCESS;
}