fork download
  1. #include<iostream>
  2. #include<cmath>
  3. #include<algorithm>
  4. #include<iomanip>
  5. #include<climits>
  6. #include<numeric>
  7. #include<set>
  8. #include<sstream>
  9. #include<map>
  10. #include<vector>
  11. #include<string>
  12. #include<regex>
  13.  
  14. using namespace std;
  15.  
  16. const long long MOD = (long long)(1e9 + 7);
  17.  
  18. vector<string> split(const string& haystack, const string& needle) {
  19. vector<string> result;
  20. size_t start_pos = 0;
  21. size_t found_pos = haystack.find(needle, start_pos);
  22. while (found_pos != string::npos) {
  23. size_t count = found_pos - start_pos;
  24. string token = haystack.substr(start_pos, count);
  25. if (!token.empty()) {
  26. result.push_back(token);
  27. }
  28. start_pos = found_pos + needle.length();
  29. found_pos = haystack.find(needle, start_pos);
  30. }
  31.  
  32. string last_token = haystack.substr(start_pos);
  33. if (!last_token.empty()) {
  34. result.push_back(last_token);
  35. }
  36. return result;
  37. }
  38.  
  39. int main() {
  40. string line;
  41. map<string, int> goals;
  42. while (getline(cin, line)) {
  43. auto parts = split(line, " - ");
  44.  
  45. int lastSpace = parts[0].find_last_of(" ");
  46. string team_one = parts[0].substr(0, lastSpace);
  47. int grade_one = stoi(parts[0].substr(lastSpace + 1));
  48.  
  49. int firstSpace = parts[1].find_first_of(" ");
  50. string team_two = parts[1].substr(firstSpace + 1);
  51. int grade_two = stoi(parts[1].substr(0, firstSpace));
  52.  
  53. goals[team_one] += grade_one;
  54. goals[team_two] += grade_two;
  55. }
  56.  
  57. vector<pair<string, int>> teams{ goals.begin(),goals.end() };
  58. sort(teams.begin(), teams.end(), [](const auto& a, const auto& b) {
  59. return a.second != b.second ? a.second > b.second:a.first < b.first;
  60. });
  61. for (auto entry : teams) {
  62. cout << entry.first << " " << entry.second << endl;
  63. }
  64. /*for (const auto& [team, score] : teams) {
  65. cout << team << " " << score << endl;
  66. }*/
  67. return 0;
  68. }
  69.  
  70.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty