Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int NUMBER_OF_MARATHONS = 12;
- const int MAX_NUMBER_PARTICIPANTS = 1000;
- struct Runner {
- char name[30];
- char surname[30];
- double times[NUMBER_OF_MARATHONS];
- };
- Runner getNew()
- {
- Runner newRunner;
- cout << "Let's add a new runner!" << endl;
- cout << "Give me a name:" << endl;
- cin >> newRunner.name;
- cout << "Give me a surname:" << endl;
- cin >> newRunner.surname;
- for (int i = 0; i < NUMBER_OF_MARATHONS; i++)
- {
- cout << "Give me his " << i + 1 << " marathon time:" << endl;
- cin >> newRunner.times[i];
- }
- return newRunner;
- }
- void slowestRunner(Runner runnersList[MAX_NUMBER_PARTICIPANTS], int size)
- {
- int slowestRunnerIndex = 0;
- double slowestPace = 100000;
- for (int i = 0; i < size; i++)
- {
- double averagePace = 0;
- cout << runnersList[i].name << endl;
- for (int j = 0; j < NUMBER_OF_MARATHONS; j++)
- {
- cout << runnersList[i].times[j] << endl;
- averagePace += runnersList[i].times[j];
- }
- averagePace /= 12;
- if (averagePace < slowestPace)
- {
- slowestPace = averagePace;
- slowestRunnerIndex = i;
- }
- }
- cout << "Slowest runner is" << endl;
- cout << runnersList[slowestRunnerIndex].name << endl;
- }
- int beatNTime(Runner a, Runner b)
- {
- int wonTheRace = 0;
- for (int i = 0; i < NUMBER_OF_MARATHONS; i++)
- {
- if (a.times[i] > b.times[i])
- {
- wonTheRace++;
- }
- }
- return wonTheRace;
- }
- int main()
- {
- int n;
- cin >> n;
- Runner runnersList[MAX_NUMBER_PARTICIPANTS];
- for (int i = 0; i < n; i++)
- {
- runnersList[i] = getNew();
- }
- slowestRunner(runnersList,n);
- cout << beatNTime(runnersList[0], runnersList[1]) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement