|
|
@ -1,21 +1,55 @@ |
|
|
#include <iostream>
|
|
|
#include <iostream>
|
|
|
#include <utility>
|
|
|
#include <utility>
|
|
|
|
|
|
#include <sstream>
|
|
|
#include <string>
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
#include <functional>
|
|
|
#include "solutions.hpp"
|
|
|
#include "solutions.hpp"
|
|
|
|
|
|
|
|
|
using namespace std; |
|
|
using namespace std; |
|
|
|
|
|
|
|
|
|
|
|
typedef std::pair<std::string, std::string>(*solution_t)(std::istream&); |
|
|
|
|
|
template <unsigned long N> void init_solutions(std::array<solution_t, N> &solutions); |
|
|
|
|
|
|
|
|
|
|
|
template <unsigned int N> |
|
|
|
|
|
pair<string, string> solve(istream&) { |
|
|
|
|
|
stringstream s; |
|
|
|
|
|
s << "solution " << N << " not implemented"; |
|
|
|
|
|
throw logic_error(s.str()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template <unsigned long I> |
|
|
|
|
|
constexpr void do_init(solution_t *solutions) { |
|
|
|
|
|
solutions[I-1] = solve<I>; |
|
|
|
|
|
do_init<I-1>(solutions); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template <> |
|
|
|
|
|
constexpr void do_init<1>(solution_t *solutions) { |
|
|
|
|
|
solutions[0] = solve<1>; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template <unsigned long N> |
|
|
|
|
|
void init_solutions(array<solution_t, N> &solutions) { |
|
|
|
|
|
do_init<N>(solutions.data()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) { |
|
|
int main(int argc, char *argv[]) { |
|
|
|
|
|
array<pair<string,string>(*)(istream&), 25> solutions; |
|
|
|
|
|
init_solutions(solutions); |
|
|
if (argc < 2) { |
|
|
if (argc < 2) { |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
int problem_number = stoi(string(argv[1])); |
|
|
int problem_number = stoi(string(argv[1])); |
|
|
solution_fn solutions[] = {solve1, solve2, solve3, solve4}; |
|
|
|
|
|
auto x = solutions[problem_number-1]; |
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
auto x = solutions.at(problem_number-1); |
|
|
auto answer = x(cin); |
|
|
auto answer = x(cin); |
|
|
cout << "Solution 1: " << answer.first << endl; |
|
|
cout << "Solution 1: " << answer.first << endl; |
|
|
cout << "Solution 2: " << answer.second << endl; |
|
|
cout << "Solution 2: " << answer.second << endl; |
|
|
|
|
|
} catch (exception const &e) { |
|
|
|
|
|
cerr << "error: " << e.what() << endl; |
|
|
|
|
|
} |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|