Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. #ifndef CODEFORCES_DEBUG_H
  2. #define CODEFORCES_DEBUG_H
  3.  
  4. #include <bits/stdc++.h>
  5.  
  6. template <typename T>
  7. std::ostream &operator<<(std::ostream &out, std::vector<std::vector<T>> const &v)
  8. {
  9. for (auto &&i : v) {
  10. for (auto &&j : i)
  11. out << j << " ";
  12. out << std::endl;
  13. }
  14. return out;
  15. }
  16.  
  17. template <typename T, size_t rows, size_t cols>
  18. std::ostream &operator<<(std::ostream &out, T (&array)[rows][cols])
  19. {
  20. for (int i = 0; i < rows; ++i) {
  21. for (int j = 0; j < cols; j++) {
  22. out << array[i][j] << " ";
  23. }
  24. out << std::endl;
  25. }
  26.  
  27. return out;
  28. }
  29.  
  30. template <size_t rows, size_t cols>
  31. std::ostream &operator<<(std::ostream &out, char (&array)[rows][cols])
  32. {
  33. for (int i = 0; i < rows; ++i) {
  34. out << array[i] << " " << std::endl;
  35. }
  36. out << std::endl;
  37.  
  38. return out;
  39. }
  40.  
  41. template <size_t rows>
  42. std::ostream &operator<<(std::ostream &out, int (&array)[rows])
  43. {
  44. for (auto &j : array) {
  45. out << j << " ";
  46. }
  47. out << std::endl;
  48.  
  49. return out;
  50. }
  51.  
  52. template <typename T, typename V>
  53. std::ostream &operator<<(std::ostream &os, const std::pair<T, V> pai)
  54. {
  55. return os << '(' << pai.first << ' ' << pai.second << ')';
  56. }
  57.  
  58. template <typename T>
  59. std::ostream &operator<<(std::ostream &os, const std::vector<T> v)
  60. {
  61. std::cout << '[';
  62.  
  63. for (auto &item : v) {
  64. std::cout << item << ",";
  65. }
  66.  
  67. std::cout << "]";
  68. return os;
  69. }
  70.  
  71. template <typename T>
  72. std::ostream &operator<<(std::ostream &os, const std::set<T> v)
  73. {
  74. std::cout << "{";
  75. for (auto p : v)
  76. std::cout << p << ",";
  77. std::cout << "}";
  78. return os;
  79. }
  80.  
  81. template <typename T, typename V>
  82. std::ostream &operator<<(std::ostream &os, const std::map<T, V> v)
  83. {
  84. std::cout << "{";
  85. for (auto p : v)
  86. std::cout << p << ",";
  87. std::cout << "}";
  88. return os;
  89. }
  90.  
  91. std::ifstream in("/home/frs/CLionProjects/codeforce/in.txt");
  92. std::ofstream out("/home/frs/CLionProjects/codeforce/out.txt");
  93.  
  94. auto cinbuf = std::cin.rdbuf(in.rdbuf());
  95. auto coutbuf = std::cout.rdbuf(out.rdbuf());
  96.  
  97. #define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
  98. template <class TH>
  99. void _dbg(const char *sdbg, TH h)
  100. {
  101. std::cout << sdbg << '=' << h << std::endl;
  102. }
  103. template <class TH, class... TA>
  104. void _dbg(const char *sdbg, TH h, TA... a)
  105. {
  106. while (*sdbg != ',')
  107. std::cout << *sdbg++;
  108. std::cout << '=' << (h) << ',';
  109. _dbg(sdbg + 1, a...);
  110. }
  111.  
  112. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement