Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.7 kB
8
Indexable
Never
#include <iostream>
#include <Windows.h> //output 
#include <algorithm> //max 
#include <map> //dictionary
#include <vector> //vector of societies
#include <algorithm> // find same societies
using namespace std;

multimap <string, string> societies;

struct athlete
{
    string name;
    string sport_soc;
    float first_try;
    float second_try;
    float third_try;
};

void GetData(athlete* list, int n)
{
    for (int i = 0; i < n; i++)
    {
        string name1, name2, name3;
        string sport_soc;
        float first_try, second_try, third_try;

        cout << "Введите ФИО спортсмена" << endl;
        cin >> name1 >> name2 >> name3;
        list[i].name = name1 + " " + name2 + " " + name3;

        cout << "Введите общество, которое представляет спортсмен" << endl;
        cin >> sport_soc;
        list[i].sport_soc = sport_soc;

        cout << "Введите результаты первой попытки" << endl;
        cin >> first_try;
        list[i].first_try = first_try;

        cout << "Введите результаты второй попытки" << endl;
        cin >> second_try;
        list[i].second_try = second_try;

        cout << "Введите результаты третьей попытки" << endl;
        cin >> third_try;
        list[i].third_try = third_try;
        
    }

}

void CalculateWinner(athlete* list, int n)
{
    string winner_name;
    string winner_soc;
    float winner_res = 0.0;

    for (int i = 0; i < n; i++)
    {
        float max_res = max(list[i].first_try, list[i].second_try, list[i].third_try);

        if (winner_res < max_res)
        {
            winner_res = max_res;
            winner_name = list[i].name;
            winner_soc = list[i].sport_soc;
        }

    }

    cout << "\n" << winner_soc << " - общество-победитель соревнований" << endl;
}

void Societies(athlete* list, int n)
{
    for (int i = 0; i < n; i++)
    {
        societies.insert(pair<string, string>(list[i].sport_soc, list[i].name));
    }
}

void ShowData(athlete* list, int n)
{
    cout << "\n" << "ФИО спортсмена - общество - результаты 3-х попыток" << endl;

    for (int i = 0; i < n; i++)
    {
        string name = list[i].name;
        string sport_soc = list[i].sport_soc;
        float first_try = list[i].first_try;
        float second_try = list[i].second_try;
        float third_try = list[i].third_try;

        cout << name << " - " << sport_soc << " - "
            << first_try << " " << second_try << " "
            << third_try << endl;
    }


    vector <string> soc;
    multimap <string, string> ::iterator it = societies.begin();
    for (it = societies.begin(); it != societies.end(); it++)
    {
        if (!(find(soc.begin(), soc.end(), it->first) != soc.end()))
        {
            soc.push_back(it->first);
        }
    }

    cout << "\n" << "Общество" << "\t" << "Количество представителей" << endl;
    for (auto word : soc)
    {
        cout << word << "\t" << societies.count(word) << endl;
    }
}

int main()
{
    SetConsoleCP(1251);
    setlocale(LC_ALL, "Russian");

    int n;
    cout << "Введите количество спортсменов" << endl;
    cin >> n;

    athlete* list = new athlete[n];
    GetData(list, n);
    CalculateWinner(list, n);
    Societies(list, n);
    ShowData(list, n);
    delete[]list;
}