This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
forked from MikeMirzayanov/testlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.hpp
72 lines (61 loc) · 2.01 KB
/
utils.hpp
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
#ifndef UTILS_H_
#define UTILS_H_
#include <filesystem>
#include <map>
#include <vector>
#include <iostream>
enum PrintFormat { Prompt, Solution };
// map for keeping the names of directories
// promptInputDirectory - directory for in files formatted for prompt
// promptInputDirectory - directory for in files formatted for the solution
const std::map<std::string, std::string> dirs = {{"promptInputDirectory", "in"},
{"solutionInputDirectory", "solution-in"}};
template <typename F, typename S>
std::ostream &operator<<(std::ostream &os, const std::pair<F, S> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
os << "{";
typename std::vector<T>::const_iterator it;
for (it = v.begin(); it != v.end(); ++it) {
if (it != v.begin()) {
os << ", ";
}
os << *it;
}
return os << "}";
}
void println() { std::cout << '\n'; }
template <typename Head, typename... Tail>
void println(Head H, Tail... T) {
std::cout << ' ' << H;
println(T...);
}
void setupDirectories() {
for (const auto &dir : dirs) {
if (!std::filesystem::create_directory(dir.second)) {
// Only warning, because you can fail to create a directory if it exists.
std::cerr << "Warning: Could not create directory " << dir << std::endl;
}
}
}
template <typename T>
concept ConvertibleToInt64_t = std::convertible_to<T, int64_t>;
template<ConvertibleToInt64_t T>
int64_t changeVectorToInt64_t(std::vector<T> &v) {
int64_t result = 0;
for (int64_t i = 0; i < v.size(); i++) {
result += (i + 1) * v[i];
}
return result;
}
template<ConvertibleToInt64_t T>
int64_t changeVectorOfPairsToInt64_t(std::vector<std::pair<T, T>> &v) {
int64_t result = 0;
for (int64_t i = 0; i < v.size(); i++) {
result += (2*i + 1) * v[i].first + (2*i + 2) * v[i].second;
}
return result;
}
#endif