-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4.2.2.cpp
67 lines (64 loc) · 1.55 KB
/
4.2.2.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
#include <iostream>
#include <stdlib.h>
#include <string>
#include <sstream>
#include <utility>
#include <vector>
#include <map>
using namespace std;
template <typename T>
ostream& operator<<(ostream& stream, const vector<T>& vector){
int size = vector.size();
int i = 0;
stream << "[";
for (auto elem : vector) {
stream << elem;
i++; // elements already displayed
//if not all elements have been displayed, type a comma and a space
if (i < size)
stream << ", ";
}
stream << "]";
return stream;
}
template <typename T, typename U>
ostream& operator<<(ostream& stream, const map<T,U>& map){
int size = map.size();
int i = 0;
stream << "{";
for (auto elem : map) {
stream << "{" << elem.first << ", " << elem.second << "}";
i++; // elements already displayed
//if not all elements have been displayed, type a comma and a space
if (i < size)
stream << ", ";
}
stream << "}";
return stream;
}
int main(){
map<int, string> a;
vector<int> b;
vector<string> c;
cout << "Input three key values(integers) for the map." << endl;
int array[3];
cin >> array[1] >> array[2] >> array[3];
cout << "Input three words for the map." << endl;
cin >> a[array[1]] >> a[array[2]] >> a[array[3]];
int element;
cout << "Input five numbers for the vector." << endl;
for (int j = 0; j < 5; j++) {
cin >> element;
b.push_back(element);
}
cout << "Input three words for the vector." << endl;
string elem;
for (int j = 0; j < 3; j++) {
cin >> elem;
c.push_back(elem);
}
cout << a << endl;
cout << b << endl;
cout << c << endl;
return 0;
}