fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define prev kundol
  4. int n, o, A, B, asum, bsum;
  5. string s, prev;
  6. string print(int a){
  7. string d = "00" + to_string(a / 60);
  8. string e = "00" + to_string(a % 60);
  9. return d.substr(d.size() - 2, 2) + ":" + e.substr(e.size() - 2, 2);
  10. }
  11.  
  12. int changeToInt(string a){
  13. return atoi(a.substr(0, 2).c_str()) * 60 + atoi(a.substr(3, 2).c_str());
  14. }
  15.  
  16. void go(int &sum, string s){
  17. sum += changeToInt(s) - changeToInt(prev);
  18. }
  19.  
  20. int main(){
  21. cin >> n;
  22. for(int i = 0; i < n; i++){
  23. cin >> o >> s;
  24. if(A > B) go(asum, s);
  25. else if(B > A) go(bsum, s);
  26. o == 1 ? A++ : B++;
  27.  
  28. prev = s;
  29. }
  30.  
  31. if(A > B) go(asum, "48:00");
  32. else if(B > A) go(bsum, "48:00");
  33.  
  34. cout << print(asum) << "\n";
  35. cout << print(bsum) << "\n";
  36. }
Success #stdin #stdout 0s 5316KB
stdin
3
1 01:10
2 21:10
2 31:30
stdout
20:00
16:30