SHARE
TWEET

Untitled

a guest Oct 13th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. struct Idiot {
  8.     string country;
  9.     string name;
  10. };
  11.  
  12. Idiot arr1[100000];
  13. Idiot arr[100000];
  14.  
  15. void merge_sort(int l, int r){
  16.     if (l == r){
  17.         return;
  18.     }
  19.     int mid = (l + r) / 2;
  20.     merge_sort(l, mid);
  21.     merge_sort(mid + 1, r);
  22.     int i = l;
  23.     int j = mid + 1;
  24.     int k = 0;
  25.     while((i < mid + 1) && (j < r + 1)){
  26.         if (arr[i].country <= arr[j].country){
  27.             arr1[k] = arr[i];
  28.             i++;
  29.             k++;
  30.         }else{
  31.             arr1[k] = arr[j];
  32.             j++;
  33.             k++;
  34.         }
  35.     }
  36.     while (i < mid + 1){
  37.         arr1[k] = arr[i];
  38.         i++;
  39.         k++;
  40.     }
  41.     while(j < r + 1){
  42.         arr1[k] = arr[j];
  43.         j++;
  44.         k++;
  45.     }
  46.     for(int m = 0; m < r - l +1; m++){
  47.         arr[l + m] = arr1[m];
  48.     }
  49.     return;
  50. }
  51.  
  52.  
  53. int main(){
  54.     ifstream cin("race.in");
  55.     ofstream cout("race.out");
  56.  
  57.     int n; cin >> n;
  58.  
  59.     for(int i = 0; i < n; i++) {
  60.         cin >> arr[i].country >> arr[i].name;
  61.     }
  62.  
  63.  
  64.     merge_sort(0, n - 1);
  65.     cout << "=== " << arr1[0].country << " ===" << endl << arr1[0].name << endl;
  66.     for (int i = 1; i < n; i++){
  67.         if (arr1[i].country != arr1[i - 1].country){
  68.             cout << "=== " << arr1[i].country << " ===" <<endl;
  69.         }
  70.         cout << arr1[i].name << endl;
  71.     }
  72.  
  73.     return 0;
  74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top