fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. const int MAX_VALUE = 10000;
  6.  
  7. void countHours(string line, int totalHours[]) {
  8. int x, y;
  9. sscanf(&line[0], "%*s %d %*s %*s %d", &x, &y);
  10. totalHours[x] += y;
  11. }
  12.  
  13. int findDiligent(int totalHours[]) {
  14. int numWorker, maxHours = 0;
  15. for (int i = 1; i < MAX_VALUE; ++i) {
  16. if (maxHours < totalHours[i]) {
  17. numWorker = i;
  18. maxHours = totalHours[i];
  19. }
  20. }
  21. return numWorker;
  22. }
  23.  
  24. int main() {
  25. int n, totalHours[MAX_VALUE + 1] = {0};
  26. string line;
  27. cin >> n;
  28. getline(cin, line);
  29. for (int i = 1; i <= n; ++i) {
  30. getline(cin, line);
  31. countHours(line, totalHours);
  32. }
  33. cout << findDiligent(totalHours);
  34. return 0;
  35. }
Success #stdin #stdout 0s 5276KB
stdin
6
Muncitorul 4 a muncit 4 ore
Muncitorul 2 a muncit 5 ore
Muncitorul 4 a muncit 10 ore
Muncitorul 3 a muncit 15 ore
Muncitorul 9 a muncit 69 ore
Muncitorul 1 a muncit 70 ore

stdout
1