My main concern is code style. Could you review this?
#pragma once
#include <time.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
#include <functional>
#include <math.h>
#include <exception>
#include "InfInt.h"
#include "Array2d.h"
template <typename ContainerT>
ContainerT splitString(const std::string & source) {
ContainerT cont;
std::stringstream ss(source);
typedef typename ContainerT::value_type ElementT;
std::copy(std::istream_iterator<ElementT>(ss), std::istream_iterator<ElementT>(), std::back_inserter(cont));
return cont;
}
template <typename T>
std::string joinString(const T & v, const std::string & delim = " ") {
std::ostringstream s;
bool empty = true;
for (const auto & i : v) {
if (empty)
empty = false;
else
s << delim;
s << i;
}
return s.str();
}
class CodeJam {
public:
std::stringstream input;
std::stringstream output;
int curCase;
int solveJam(const std::string & data) {
int res = 0;
std::cout << "Solving jam:" << std::endl << std::endl;
try {
input.clear();
output.clear();
auto inputFile = "Data\\" + data + ".in";
std::ifstream finput(inputFile);
if (!finput.is_open())
throw std::runtime_error("Can not open input file " + inputFile);
auto outputFile = "Data\\" + data + ".out";
std::ofstream foutput(outputFile);
if (!foutput.is_open())
throw std::runtime_error("Can not open output file " + outputFile);
input << finput.rdbuf();
input.seekg(0);
auto elapsedTime = clock();
res = solveAll();
elapsedTime = clock() - elapsedTime;
foutput << output.rdbuf();
finput.close();
foutput.close();
std::cout << std::endl;
std::cout << "Success! Finished " << res << " tests in " << elapsedTime << " ms" << std::endl;
} catch (const std::exception & e) {
std::cout << "Error: " << e.what() << std::endl;
}
std::cout << std::endl;
system("pause");
return res;
}
protected:
virtual int solveAll() {
int testCases;
readln(testCases);
for (curCase = 1; curCase <= testCases; ++curCase) {
solve(curCase);
std::cout << "Test " << curCase << " of " << testCases << std::endl;
};
return testCases;
}
virtual void solve(int task) = 0;
public:
std::string readLine() {
std::string line;
std::getline(input, line);
return line;
}
template<typename T>
T readLine() {
std::string line;
std::getline(input, line);
T list = splitString<T>(line);
return list;
}
std::vector<int> readInts() {
return readLine<std::vector<int>>();
}
std::vector<std::string> readStrings() {
return readLine<std::vector<std::string>>();
}
std::vector<double> readDoubles() {
return readLine<std::vector<double>>();
}
void readln() {
readLine();
}
template <typename T>
void readln(T & t) {
input >> t;
input.ignore();
}
template <typename First, typename... Rest>
void readln(First & first, Rest &... rest) {
input >> first;
readln(rest...);
}
template <typename T>
void writeResult(T value) {
output << "Case #" << curCase << ": " << value << std::endl;
};
};