desislava_topuzakova

06. Easter Competition

Feb 20th, 2021
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int countKozunaks;
  9.     cin >> countKozunaks;
  10.     cin.ignore();
  11.  
  12.     int maxPoints = INT_MIN; //броят на максималните точки
  13.     string maxBaker = "";
  14.     for (int kozunak = 1; kozunak <= countKozunaks; kozunak++)
  15.     {
  16.         string baker;
  17.         getline(cin, baker);
  18.         int totalPoints = 0;
  19.         string command; //оценка(5) или Stop
  20.         getline(cin, command);
  21.         while(command != "Stop") {
  22.             //оценка -> "10" -> 10
  23.             int grade = stoi(command);
  24.             totalPoints += grade;
  25.  
  26.             getline(cin, command);
  27.         }
  28.         //общ брой точки за пекар
  29.         cout << baker << " has " << totalPoints << " points." << endl; 
  30.         //проверка дали точките на този пекар са максималните
  31.         if (totalPoints > maxPoints) {
  32.             maxPoints = totalPoints;
  33.             maxBaker = baker;
  34.             cout << baker << " is the new number 1!" << endl;
  35.         }
  36.     }
  37.  
  38.     cout << maxBaker << " won competition with " << maxPoints << " points!" << endl;
  39.  
  40.  
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment