Advertisement
Spocoman

Football League

Sep 19th, 2023 (edited)
1,020
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8.     int stadiumCapacity, fanCount, sectorA = 0, sectorB = 0, sectorV = 0, sectorG = 0;
  9.     cin >> stadiumCapacity >> fanCount;
  10.  
  11.     char currentFanSector;
  12.  
  13.     for (int i = 0; i < fanCount; i++) {
  14.         cin >> currentFanSector;
  15.         if (currentFanSector == 'A') {
  16.             sectorA++;
  17.         }
  18.         else if (currentFanSector == 'B') {
  19.             sectorB++;
  20.         }
  21.         else if (currentFanSector == 'V') {
  22.             sectorV++;
  23.         }
  24.         else {
  25.             sectorG++;
  26.         }
  27.     }
  28.  
  29.     printf("%.2f%%\n", 100.0 * sectorA / fanCount);
  30.     printf("%.2f%%\n", 100.0 * sectorB / fanCount);
  31.     printf("%.2f%%\n", 100.0 * sectorV / fanCount);
  32.     printf("%.2f%%\n", 100.0 * sectorG / fanCount);
  33.     printf("%.2f%%\n", 100.0 * fanCount / stadiumCapacity);
  34.  
  35.     return 0;
  36. }
  37.  
  38. Решение с колекция и for(each):
  39.  
  40. #include <iostream>
  41. #include <map>
  42. #include <string>
  43.  
  44. using namespace std;
  45.  
  46. int main() {
  47.     map <char, int> sectors = { {'A',0},{'B',0},{'V',0},{'G',0} };
  48.  
  49.     int stadiumCapacity, fanCount;
  50.     cin >> stadiumCapacity >> fanCount;
  51.  
  52.     char currentFanSector;
  53.  
  54.     for (int i = 0; i < fanCount; i++) {
  55.         cin >> currentFanSector;
  56.  
  57.         sectors[currentFanSector]++;
  58.     }
  59.    
  60.     for (char sector : {'A', 'B', 'V', 'G'}) {
  61.         printf("%.2f%%\n", 100.0 * sectors[sector] / fanCount);
  62.     }
  63.    
  64.     printf("%.2f%%\n", 100.0 * fanCount / stadiumCapacity);
  65.  
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement