Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- using namespace std;
- struct runner
- {
- int place;
- string name;
- string country;
- };
- void mergeSort(vector<runner>& a, int start, int end)
- {
- if (start + 1 >= end)
- {
- return;
- }
- mergeSort(a, start, start + (end - start) / 2);
- mergeSort(a, start + (end - start) / 2, end);
- vector<runner> b;
- int b1 = start;
- int e1 = start + (end - start) / 2;
- int b2 = start + (end - start) / 2;
- int e2 = end;
- while (b.size() < end - start)
- {
- if (b1 == e1 || ((b2 < e2) &&(a[b2].country < a[b1].country)))
- {
- b.push_back(a[b2]);
- b2++;
- }
- else
- {
- b.push_back(a[b1]);
- b1++;
- }
- }
- for (int i = start; i < end; i++)
- {
- a[i] = b[i-start];
- }
- }
- int main()
- {
- ifstream input("race.in");
- ofstream output("race.out");
- vector<runner> a;
- int n = 0;
- input >> n;
- a.resize(n);
- string inp_country;
- string inp_runner;
- for (int i = 0; i < n; ++i)
- {
- input >> inp_country >> inp_runner;
- a[i].name = inp_runner;
- a[i].place = i+1;
- a[i].country = inp_country;
- }
- mergeSort(a,0,n);
- string curr_country = "";
- for (int i = 0; i < n; i++)
- {
- if (curr_country != a[i].country)
- {
- curr_country = a[i].country;
- cout << "=== " << a[i].country << " ===" << endl;
- }
- cout << a[i].name << endl;
- }
- input.close();
- output.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement