-
Notifications
You must be signed in to change notification settings - Fork 0
/
DictSTL.cpp
72 lines (62 loc) · 1.44 KB
/
DictSTL.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <unordered_map>
using namespace std;
class Estudiante
{
public:
string nombre;
int matricula;
Estudiante()
{
nombre="";
matricula=0;
}
Estudiante(string n, int m)
{
nombre=n;
matricula=m;
}
bool operator==(const Estudiante& otro) const
{
if(this->matricula == otro.matricula)
{
return true;
}
return false;
}
};
struct HashEstudiante{
size_t operator()(const Estudiante& e) const
{
return hash<int>()(e.matricula);
}
};
int main(){
unordered_map<string, Estudiante> escuela;
escuela.insert({"juan", Estudiante("juan", 14214)});
escuela["juan"].matricula=14215;
cout<<escuela["juan"].matricula<<endl;
Estudiante a1("juan", 12412);
Estudiante a2("mercedes", 1231);
unordered_map<Estudiante, int, HashEstudiante> clase;
clase.insert({a1, 100});
/*unordered_map<string, int> cal;
cal.insert(pair<string, int>("juan", 95));
cal.insert({"ana", 90});
cal["jose"]=93;
//auto es pair<string,int>
/*for(auto elemento: cal){
cout<<elemento.first<<":"<<elemento.second<<endl;
}
//auto es unodered_map<string, int>::iterator
for(auto i=cal.begin(); i!=cal.end(); i++){
cout<<(*i).first<<":"<<i->second<<endl;
}
auto pos=cal.find("joe");
if(pos!=cal.end()){
cout<<"El valor de la llave es "<<pos->second<<endl;
}else{
cout<<"No se encontro un valor con esa llave"<<endl;
}*/
return 0;
}