stat.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // =====================================================================================
  2. //
  3. // Filename: stat.cc
  4. //
  5. // Description: read one result
  6. //
  7. // Version: 1.0
  8. // Created: 2018年 03月 16日 星期五 22:02:12 CST
  9. // Revision: none
  10. // Compiler: g++
  11. //
  12. // Author: Jinkun Lin, jkunlin@gmail.com
  13. // Organization: School of EECS, Peking University
  14. //
  15. // =====================================================================================
  16. #include <iostream>
  17. #include <fstream>
  18. #include <sstream>
  19. #include <string>
  20. using namespace std;
  21. int main(int argc, char const *argv[]) {
  22. if (argc != 2) {
  23. return 1;
  24. }
  25. string filename = argv[1];
  26. ifstream infile(filename);
  27. if (!infile) {
  28. std::cout << "file" << std::endl;
  29. return 1;
  30. }
  31. size_t b = filename.find_last_of('_') + 5;
  32. size_t e = filename.find_last_of('.');
  33. string seed = filename.substr(b, e - b);
  34. double cutoff = 120;
  35. string line, tmp;
  36. int size, old_size = 0;
  37. double time, old_time = 0;
  38. char exact = 'h';
  39. while (getline(infile, line)) {
  40. istringstream is(line);
  41. is >> tmp >> size >> time;
  42. if (time > cutoff) {
  43. size = old_size;
  44. time = old_time;
  45. }
  46. else {
  47. old_size = size;
  48. old_time = time;
  49. }
  50. }
  51. std::cout << seed << '\t' << size << '\t' << time << '\t' << exact << std::endl;
  52. return 0;
  53. }