Advertisement
cacodemon665

Лаба 7 Вариант 7

Oct 25th, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. #include "pch.h" //для версий вижлы старше последних версий 2017 здесь должно быть #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. struct SpData
  7. {
  8.     char country[50];
  9.     char team_name[50];
  10.     char fio[50];
  11.     int id;
  12.     int age;
  13.     int height;
  14.     int weight;
  15. };
  16.  
  17.  
  18. int main()
  19. {
  20.     int n, teams_cnt = 0;
  21.     cout << "Enter number of people:";
  22.     cin >> n;
  23.  
  24.     SpData data[1000];
  25.     char* teams[1000];
  26.     int ages[1000], cnt[1000];
  27.  
  28.  
  29.     for (int i = 0; i < n; i++)
  30.     {
  31.         cout << i + 1 << endl;
  32.  
  33.         cin.ignore(1, '\n');
  34.  
  35.         cout << "Enter country name: ";
  36.         cin.getline(data[i].country, 50);
  37.         cout << "Enter team name: ";
  38.         cin.getline(data[i].team_name, 50);
  39.         cout << "Enter full name: ";
  40.         cin.getline(data[i].fio, 50);
  41.         cout << "Enter ID: ";
  42.         cin >> data[i].id;
  43.         cout << "Enter age: ";
  44.         cin >> data[i].age;
  45.         cout << "Enter height: ";
  46.         cin >> data[i].height;
  47.         cout << "Enter weight: ";
  48.         cin >> data[i].weight;
  49.  
  50.         bool flag = true;
  51.  
  52.         for (int j = 0; j < teams_cnt; j++)
  53.         {
  54.             if (strcmp(data[i].team_name, teams[j]) == 0)
  55.             {
  56.                 flag = false;
  57.                 ages[j] += data[i].age;
  58.                 cnt[j]++;
  59.                 break;
  60.             }
  61.         }
  62.  
  63.         if (flag)
  64.         {
  65.             teams[teams_cnt] = data[i].team_name;
  66.             ages[teams_cnt] = data[i].age;
  67.             cnt[teams_cnt]++;
  68.             teams_cnt++;
  69.         }
  70.     }
  71.  
  72.     int min_ind = 0;
  73.     double min = 1000;
  74.  
  75.     for (int i = 0; i < teams_cnt; i++)
  76.     {
  77.         double average = ages[i] / (double)cnt[i];
  78.  
  79.         if (average < min)
  80.         {
  81.             min = average;
  82.             min_ind = i;
  83.         }
  84.     }
  85.  
  86.     cout << "Team name: " << teams[min_ind] << endl;
  87.     cout << "Age: " << min;
  88.     cout << "Players: " << endl;
  89.  
  90.     for (int i = 0; i < n; i++)
  91.     {
  92.         if (strcmp(data[i].team_name, teams[min_ind]) == 0)
  93.         {
  94.             cout << "Country: " << data[i].country << endl;
  95.             cout << "Team: " << data[i].team_name << endl;
  96.             cout << "Full name: " << data[i].fio << endl;
  97.             cout << "ID: " << data[i].id << endl;
  98.             cout << "Age: " << data[i].age << endl;
  99.             cout << "Height: " << data[i].height << endl;
  100.             cout << "Weight: " << data[i].weight << endl;
  101.         }
  102.     }
  103.  
  104.     return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement