History Grading


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*
  2.  * grading.cpp
  3.  *
  4.  * Created on: Jan 27, 2011
  5.  * Author: dirk
  6.  */
  7.  
  8. #include "lcs.hpp"
  9.  
  10. #include <vector>
  11. #include <fstream>
  12. #include <iostream>
  13. #include <sstream>
  14. #include <iterator>
  15. #include <algorithm>
  16. #include <string>
  17.  
  18. typedef unsigned* EventOrder;
  19.  
  20. inline void transfer(EventOrder const &ori, EventOrder &tra, size_t size) {
  21. for (size_t i = 0; i < size; ++i) {
  22. tra[ori[i] - 1] = i + 1;
  23. }
  24. }
  25.  
  26. int main(int argc, char **argv) {
  27. std::ifstream fin(argv[1]);
  28. size_t n(0), sum(0);
  29.  
  30. fin >> n;
  31. EventOrder eo_tmp = new unsigned[n], eo_ans = new unsigned[n];
  32. for (size_t i = 0; i < n; ++i) {
  33. fin >> eo_tmp[i];
  34. }
  35. transfer(eo_tmp, eo_ans, n);
  36.  
  37. EventOrder eo_input = new unsigned[n];
  38. LCS_NOANS<> lcs(n);
  39. for (;;) {
  40. if (!(fin >> eo_tmp[0])) {
  41. break;
  42. }
  43. for (size_t i = 1; i < n; ++i) {
  44. fin >> eo_tmp[i];
  45. }
  46. transfer(eo_tmp, eo_input, n);
  47.  
  48. lcs.Compute(eo_ans, eo_ans + n, n, eo_input, eo_input + n, n);
  49. sum += lcs.Length();
  50. }
  51. std::cout << sum << '\n';
  52.  
  53. delete[] eo_tmp;
  54. delete[] eo_ans;
  55. delete[] eo_input;
  56. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.