fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n;
  7. cin >> n;
  8. cin.ignore();
  9.  
  10. const int MAX_WORKERS = 10001;
  11. int workHours[MAX_WORKERS] = {0};
  12.  
  13. for (int i = 0; i < n; ++i) {
  14. string line;
  15. getline(cin, line);
  16. int id = 0, hours = 0;
  17. bool foundId = false, foundHours = false;
  18. for (size_t j = 0; j < line.size(); ++j) {
  19. if (line[j] >= '0' && line[j] <= '9') {
  20. int number = 0;
  21. while (j < line.size() && line[j] >= '0' && line[j] <= '9') {
  22. number = number * 10 + (line[j] - '0');
  23. ++j;
  24. }
  25. if (!foundId) {
  26. id = number;
  27. foundId = true;
  28. } else if (!foundHours) {
  29. hours = number;
  30. foundHours = true;
  31. }
  32. }
  33. }
  34. workHours[id] += hours;
  35. }
  36. int maxHours = 0, bestWorker = 0;
  37. for (int i = 1; i < MAX_WORKERS; ++i) {
  38. if (workHours[i] > maxHours) {
  39. maxHours = workHours[i];
  40. bestWorker = i;
  41. }
  42. }
  43. cout << bestWorker;
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0.01s 5288KB
stdin
5
Muncitorul 1 a muncit 10 ore
Muncitorul 23 a muncit 5 ore
Muncitorul 3 a muncit 3 ore
Muncitorul 23 a muncit 11 ore
Muncitorul 1 a muncit 2 ore
stdout
23