map
// map<A, B>
template<typename A, typename B>
ostream &operator <<(ostream &os, const map<A, B> &M) {
os << ‘[‘;
for (auto it = M.begin(); it != M.end(); ++it) {
os << ‘(‘ << it -> first << ": " << it -> second << ‘)‘;
++it;
if (it != M.end()) {
os << ", ";
}
--it;
}
os << ‘]‘;
return os;
}
// unordered_map<A, B>
template<typename A, typename B>
ostream &operator <<(ostream &os, const unordered_map<A, B> &M) {
os << ‘[‘;
for (auto it = M.begin(); it != M.end(); ++it) {
os << ‘(‘ << it -> first << ": " << it -> second << ‘)‘;
++it;
if (it != M.end()) {
os << ", ";
}
--it;
}
os << ‘]‘;
return os;
}
set
// set<T>
template<typename T>
ostream &operator <<(ostream &os, const set<T> &S) {
os << ‘{‘;
for (auto it = S.begin(); it != S.end(); ++it) {
os << *it;
if (++it != S.end()) {
os << ", ";
}
--it;
}
os << ‘}‘;
return os;
}
// unordered_set<T>
template<typename T>
ostream &operator <<(ostream &os, const unordered_set<T> &S) {
os << ‘{‘;
for (auto it = S.begin(); it != S.end(); ++it) {
os << *it;
if (++it != S.end()) {
os << ", ";
}
--it;
}
os << ‘}‘;
return os;
}
// multiset<T>
template<typename T>
ostream &operator <<(ostream &os, const multiset<T> &S) {
os << ‘{‘;
for (auto it = S.begin(); it != S.end(); ++it) {
os << *it;
if (++it != S.end()) {
os << ", ";
}
--it;
}
os << ‘}‘;
return os;
}
vector
// vector<T>
template<typename T>
ostream &operator <<(ostream &os, const vector<T> &V) {
os << ‘[‘;
for (int i = 0; i < V.size(); ++i) {
os << V[i];
if ((i + 1) ^ V.size())
os << ", ";
}
os << ‘]‘;
return os;
}
// vector<pair<A, B>>
template<typename A, typename B>
ostream &operator <<(ostream &os, const vector<pair<A, B>> &V) {
os << ‘[‘;
for (int i = 0; i < V.size(); ++i) {
os << ‘(‘ << V[i].first << ", " << V[i].second << ‘)‘;
if ((i + 1) ^ V.size())
os << ", ";
}
os << ‘]‘;
return os;
}
stack
template<typename T>
ostream &operator <<(ostream &os, stack<T> S) {
os << "\n- - - TOP - - -\n";
while (!S.empty()) {
os << S.top();
S.pop();
os << ‘\n‘;
}
os << "- - - BOTTOM - - -\n";
return os;
}
queue
// priority_queue<T>
template<typename T>
ostream &operator <<(ostream &os, priority_queue<T> Q) {
os << ‘[‘;
while (!Q.empty()) {
os << Q.top();
Q.pop();
if (!Q.empty()) {
os << ", ";
}
}
os << ‘]‘;
return os;
}
template<typename T>
ostream &operator <<(ostream &os, priority_queue<T, vector<T>, greater<T>> Q) {
os << ‘[‘;
while (!Q.empty()) {
os << Q.top();
Q.pop();
if (!Q.empty()) {
os << ", ";
}
}
os << ‘]‘;
return os;
}
// queue<T>
template<typename T>
ostream &operator <<(ostream &os, queue<T> Q) {
os << ‘[‘;
while (!Q.empty()) {
os << Q.front();
Q.pop();
if (!Q.empty()) {
os << ", ";
}
}
os << ‘]‘;
return os;
}
// deque<T>
template<typename T>
ostream &operator <<(ostream &os, deque<T> Q) {
os << ‘[‘;
while (!Q.empty()) {
os << Q.front();
Q.pop_front();
if (!Q.empty()) {
os << ", ";
}
}
os << ‘]‘;
return os;
}
debug