/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* * grading.cpp * * Created on: Jan 27, 2011 * Author: dirk */ #include "lcs.hpp" #include <vector> #include <fstream> #include <iostream> #include <sstream> #include <iterator> #include <algorithm> #include <string> typedef unsigned* EventOrder; inline void transfer(EventOrder const &ori, EventOrder &tra, size_t size) { for (size_t i = 0; i < size; ++i) { tra[ori[i] - 1] = i + 1; } } int main(int argc, char **argv) { std::ifstream fin(argv[1]); size_t n(0), sum(0); fin >> n; EventOrder eo_tmp = new unsigned[n], eo_ans = new unsigned[n]; for (size_t i = 0; i < n; ++i) { fin >> eo_tmp[i]; } transfer(eo_tmp, eo_ans, n); EventOrder eo_input = new unsigned[n]; LCS_NOANS<> lcs(n); for (;;) { if (!(fin >> eo_tmp[0])) { break; } for (size_t i = 1; i < n; ++i) { fin >> eo_tmp[i]; } transfer(eo_tmp, eo_input, n); lcs.Compute(eo_ans, eo_ans + n, n, eo_input, eo_input + n, n); sum += lcs.Length(); } std::cout << sum << '\n'; delete[] eo_tmp; delete[] eo_ans; delete[] eo_input; }