-
Notifications
You must be signed in to change notification settings - Fork 0
/
defs.h
87 lines (72 loc) · 1.49 KB
/
defs.h
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
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef DEFS_H
#define DEFS_H
#include<cassert>
#include<cmath>
#include<string>
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<cstdarg>
#include<algorithm>
using namespace std;
template<class T, class U>
ostream & operator << (ostream &out, const map<T,U> & m) {
typename map<T,U>::const_iterator it;
for (it = m.begin(); it != m.end(); it++) {
out << it->first << " -> " << it->second << endl;
}
return out;
}
//print vector of vectors
template<class T>
ostream & operator << (ostream & out, const vector<vector<T > > & v) {
out << v.size() << endl;
if (v.size() != 0) {
out << v[0];
for (int i = 1; i < v.size(); i++) out << endl << v[i];
}
return out;
}
//read vector of vectors
template<class T>
istream & operator >> (istream & in, vector<vector<T > > & v) {
int count;
vector<T> row;
in >> count;
v.reserve(count);
for (int i = 0; i < count; i++) {
row.clear();
in >> row;
v.push_back(row);
}
return in;
}
//print vector of T
template<class T>
ostream & operator << (ostream & out, const vector<T> & v) {
out << v.size() << '\t';
if (v.size() != 0) {
out << v[0];
for (int i = 1; i < v.size(); i++) out << '\t' << v[i];
}
return out;
}
//read vector of T
template<class T>
istream & operator >> (istream & in, vector<T> & v) {
int count;
T val;
in >> count;
v.reserve(count);
for (int i = 0; i < count; i++) {
in >> val;
v.push_back(val);
}
return in;
}
#endif