fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <ctime>
  4. #include <map>
  5. #include <limits>
  6. using namespace std;
  7.  
  8. template< char C >
  9. std::istream& skip( std::istream& in )
  10. {
  11. return in.ignore( std::numeric_limits< std::streamsize >::max(), C );
  12. }
  13.  
  14. struct opt // opt für optional; liest ein int, wenn eine Zahl kommt, sonst wird der Wert =0 gesetzt
  15. {
  16. explicit opt( int& value )
  17. : value_( value )
  18. {}
  19. friend std::istream& operator>>( std::istream& in, opt o ) // Lesefunktion für den Wrapper 'opt'
  20. {
  21. char c;
  22. if( in >> c && in.putback( c ) ) // lese das nächste Zeichen 'c' und stelle es auch gleich zurück!
  23. {
  24. if( ('0' <= c && c <= '9') || c == '-' || c == '+' ) // könnte eine Zahl sein
  25. in >> o.value_; // dann lese die Zahl
  26. else
  27. o.value_ = 0; // sonst definiert auf 0 setzen
  28. }
  29. return in;
  30. }
  31. private:
  32. int& value_;
  33. };
  34.  
  35. int main()
  36. {
  37. map<string, int> m; // Variablen so lokal wie möglich anlegen
  38.  
  39. std::istream & log = std::cin;
  40.  
  41. string name1;
  42. int value;
  43. string dpsorheal; //<-- hier optional lesen -->
  44. // Format: " <Zeit> | <name1> | <name2> |<skillname> | [<value>] | <dpsorheal> | ..Rest..EOL"
  45. while( getline( getline( log >> skip<'|'>, name1, '|' ) >> skip<'|'> >> skip<'|'> >> opt(value) >> skip<'|'>, dpsorheal, '|' ) >> skip<'\n'> )
  46. { // usw.
  47. m[name1]+=value;
  48. }
  49.  
  50. for(map<string, int>::iterator iter=m.begin(); iter!=m.end(); ++iter)
  51. {
  52. cout << iter->first << " = " << iter->second << endl;
  53. }
  54.  
  55. return 0;
  56. }
  57.  
  58.  
Success #stdin #stdout 0s 3480KB
stdin
21:39:51.992|Respektlos|Tobiasvon|Salvation|1295|H|
21:39:51.992|Respektlos|Schlitzohr|Salvation|725|H|
21:39:52.271|Respektlos|Tribunus|Rejuvenate|760|H|
21:39:53.007|Tobia|Eleraana|Salvation|725|H|
21:39:53.007|Tobi|Racta|Salvation|1283|H|
21:39:53.007|Tobi|Sephone|Salvation|1283|H|
21:39:53.007|Respektlos|Respektlos|Salvation|783|H|
21:39:53.008|Respektlos|Tribunus|Salvation|1258|H|
21:39:53.008|Tobi|Tobiasvon|Salvation|747|H|
21:39:53.008|Tobi|Schlitzohr|Salvation|725|H|
21:39:54.074|Respektlos|Racta|Salvation|1283|H|
21:39:54.074|Respektlos|Eleraana|Salvation|725|H|
21:39:54.074|Respektlos|Sephone|Salvation|740|H|
21:39:54.075|Respektlos|Respektlos|Salvation|1357|H|
21:39:54.075|Respektlos|Tribunus|Salvation|725|H|
21:39:54.075|Respektlos|Tobi|Salvation|747|H|
21:39:54.075|Respektlos|Schlitzohr|Salvation|725|H|
21:39:54.305|Respektlos|Respektlos|ExitCombat||EC|
stdout
Respektlos = 11123
Tobi = 4038
Tobia = 725