mirror of
https://gitlab.com/mfocko/Codeforces.git
synced 2024-11-09 13:49:06 +01:00
chore(cpp): improve the template
* add missing headers: ‹bit›, ‹map›, ‹queue› and ‹set› * name the namespaces * math * introduce ‹MODULO› for big numbers in problems * input * implement ‹load_vector› * output * implement ‹operator<<› for ‹std::pair› * implement ‹yesno› as shortcut for YES/NO answers * implement ‹LOOP(n)› for quick range-like for-loops * make ‹N› test cases the default Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
0bfc6f808e
commit
663472e5da
1 changed files with 58 additions and 6 deletions
|
@ -1,18 +1,31 @@
|
|||
#include <algorithm>
|
||||
#include <bit>
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
template <typename T, typename U>
|
||||
std::ostream &operator<<(std::ostream &s, std::pair<T, U> const &p) {
|
||||
return s << p.first << " " << p.second;
|
||||
}
|
||||
|
||||
namespace helpers {
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace math {
|
||||
|
||||
static constexpr int32_t MODULO = 1000000007;
|
||||
|
||||
long pow(long base, long exp) {
|
||||
if (exp == 0) return 1;
|
||||
long half = pow(base, exp / 2);
|
||||
|
@ -20,6 +33,27 @@ long pow(long base, long exp) {
|
|||
return half * half * base;
|
||||
}
|
||||
|
||||
} // namespace math
|
||||
|
||||
namespace input {
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> load_vector(std::size_t size) {
|
||||
std::vector<T> result{};
|
||||
|
||||
for (auto i = 0u; i < size; ++i) {
|
||||
T x;
|
||||
std::cin >> x;
|
||||
result.push_back(std::move(x));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace input
|
||||
|
||||
namespace output {
|
||||
|
||||
template <typename T>
|
||||
inline void answer(const T &ans) {
|
||||
cout << ans << "\n";
|
||||
|
@ -28,9 +62,28 @@ inline void answer(const T &ans) {
|
|||
inline void yes() { cout << "YES\n"; }
|
||||
inline void no() { cout << "NO\n"; }
|
||||
|
||||
inline void yesno(bool ans) {
|
||||
if (ans) {
|
||||
yes();
|
||||
} else {
|
||||
no();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace output
|
||||
|
||||
using namespace math;
|
||||
using namespace input;
|
||||
using namespace output;
|
||||
|
||||
#define LOOP(n) for (auto i = 0; i < n; ++i)
|
||||
|
||||
} // namespace helpers
|
||||
|
||||
namespace {
|
||||
// for ‹N› test cases, uncomment for single test case
|
||||
// #define SINGLE
|
||||
|
||||
namespace solution {
|
||||
|
||||
using namespace std;
|
||||
using namespace helpers;
|
||||
|
@ -39,10 +92,9 @@ void solve() {
|
|||
// TODO
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace solution
|
||||
|
||||
// for single test case, comment out for ‹N› test cases
|
||||
#define SINGLE
|
||||
using namespace solution;
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
|
@ -58,7 +110,7 @@ int main(void) {
|
|||
|
||||
#ifdef SINGLE
|
||||
|
||||
solve();
|
||||
solution::solve();
|
||||
|
||||
#else
|
||||
|
||||
|
@ -67,7 +119,7 @@ int main(void) {
|
|||
std::cin >> N >> std::ws;
|
||||
|
||||
for (auto i = 0; i < N; ++i) {
|
||||
solve();
|
||||
solution::solve();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue