fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4. #include <sstream>
  5. #include <vector>
  6.  
  7. // our "input" stream:
  8. std::istringstream in(
  9. R"(CallStarted_Cap900 10.160.159.37 32514 unid to 10.9.11.66 32740 RABIA-TUJIMET-CERYAN at 2015 04 21 16 33 54 921.waa_end
  10. CallStartedAck_Cap900 10.160.159.37 32514 unid to 10.9.11.66 32740 RABIA-TUJIMET-CERYAN at 2015 04 21 16 33 54 921.waa_end
  11. CallStarted_Cap900 10.9.11.61 32572 3051905 to 10.9.11.18 39994 79970056 at 2015 04 21 16 33 54 994.waa_end
  12. CallStartedAck_Cap900 10.9.11.61 32572 3051905 to 10.9.11.18 39994 79970056 at 2015 04 21 16 33 54 994.waa_end
  13. CallStarted_Cap900 10.160.167.34 32514 unid to 10.9.11.61 32580 RGorusme at 2015 04 21 16 33 55 035.waa_end
  14. CallStartedAck_Cap900 10.160.167.34 32514 unid to 10.9.11.61 32580 RGorusme at 2015 04 21 16 33 55 035.waa_end
  15. )");
  16.  
  17. bool less_than(const std::string& a, const std::string& b)
  18. {
  19. // error checking should be done here.
  20. return a.substr(a.find(' ')) < b.substr(b.find(' '));
  21. }
  22.  
  23. bool equal(const std::string& a, const std::string& b)
  24. {
  25. // error checking should be done here.
  26. return a.substr(a.find(' ')) == b.substr(b.find(' '));
  27. }
  28.  
  29. int main()
  30. {
  31. std::ostream& out = std::cout;
  32.  
  33. std::string line;
  34. std::vector<std::string> lines;
  35. while (getline(in, line))
  36. lines.push_back(line);
  37.  
  38. std::sort(lines.begin(), lines.end(), less_than);
  39.  
  40. bool previous_output = false;
  41. for (std::size_t i = 0, j = 0; i != lines.size(); i = j)
  42. {
  43. if (previous_output)
  44. out << std::string(40, '-') << '\n';
  45.  
  46. while (j != lines.size() && equal(lines[i], lines[j]))
  47. out << lines[j++] << '\n';
  48.  
  49. previous_output = true;
  50. }
  51. }
Success #stdin #stdout 0s 3236KB
stdin
Standard input is empty
stdout
CallStarted_Cap900 10.160.159.37 32514 unid to 10.9.11.66 32740 RABIA-TUJIMET-CERYAN at 2015 04 21 16 33 54 921.waa_end
CallStartedAck_Cap900 10.160.159.37 32514 unid to 10.9.11.66 32740 RABIA-TUJIMET-CERYAN at 2015 04 21 16 33 54 921.waa_end
----------------------------------------
CallStarted_Cap900 10.160.167.34 32514 unid to 10.9.11.61 32580 RGorusme at 2015 04 21 16 33 55 035.waa_end
CallStartedAck_Cap900 10.160.167.34 32514 unid to 10.9.11.61 32580 RGorusme at 2015 04 21 16 33 55 035.waa_end
----------------------------------------
CallStarted_Cap900 10.9.11.61 32572 3051905 to 10.9.11.18 39994 79970056 at 2015 04 21 16 33 54 994.waa_end
CallStartedAck_Cap900 10.9.11.61 32572 3051905 to 10.9.11.18 39994 79970056 at 2015 04 21 16 33 54 994.waa_end