Advertisement
AdamTheGreat

Untitled

Jul 15th, 2022
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4.  
  5. int main(void) {
  6. map<string, int> cows;
  7. int n;
  8. cin >> n;
  9. string names[7] = {"Bessie", "Elsie", "Daisy", "Gertie", "Annabelle", "Maggie", "Henrietta"};
  10. for (int i = 0; i < 7; i++) {
  11. cows[names[i]] = 0;
  12. }
  13. for (int i = 0; i < n; i++) {
  14. string name;
  15. int milk;
  16. cin >> name >> milk;
  17. cows[name] += milk;
  18. }
  19. int least = 100000;
  20. for (int i = 0; i < cows.size(); i++) {
  21. if (cows[names[i]] < least) {
  22. least = cows[names[i]];
  23. cows.erase(names[i]);
  24. } else if (cows[names[i]] == least) {
  25. cows.erase(names[i]);
  26. }
  27. }
  28. int second_least = 100000;
  29. string second_least_cow = "";
  30. for (int i = 0; i < cows.size(); i++) {
  31. if (cows[names[i]] < second_least) {
  32. second_least_cow = names[i];
  33. second_least = cows[names[i]];
  34. } else if (cows[names[i]] == second_least) {
  35. second_least_cow = "Tie";
  36. }
  37. }
  38. cout << second_least_cow << endl;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement