Advertisement
Pit_Anonim

Untitled

Dec 15th, 2021
836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. const int n = 3; //Input matrix size (n x n)
  4. const int _n = n + 1;
  5.  
  6. int global_i = 1;
  7. int mass_index[_n], mass_offer[_n];
  8. int massA[_n][_n], massB[_n][_n];
  9.  
  10.  
  11. int make_offer(int count){
  12.     int offer;
  13.  
  14.     offer = massA[count][mass_index[count]];
  15.    
  16.     if (mass_offer[offer] == -1) {
  17.         mass_offer[offer] = count;
  18.         return 0;
  19.     }
  20.     else {
  21.         for (int i = 1;i < _n; i++) {
  22.             if ((massB[offer][i] == mass_offer[offer]) || (massB[offer][i] == count))
  23.                 if (massB[offer][i] == mass_offer[offer]) {
  24.                     mass_index[count]++;
  25.                     return count;
  26.                 }
  27.                 else {
  28.                     int x = mass_offer[offer];
  29.                     mass_index[mass_offer[offer]]++;
  30.                     mass_offer[offer] = count;
  31.                     return x;
  32.                 }
  33.         }
  34.     }
  35. }
  36.  
  37. int main(){
  38.     for (int i = 1; i < _n; i++){
  39.         mass_index[i] = 1;
  40.         mass_offer[i] = -1;
  41.     }
  42.  
  43.     for (int i = 1; i < _n; i++)
  44.         for (int j = 1; j < _n; j++)
  45.             std::cin>>massA[i][j];
  46.  
  47.     for (int i = 1; i < _n; i++)
  48.         for (int j = 1; j < _n; j++)
  49.             std::cin>>massB[i][j];
  50.  
  51.  
  52.     int x;
  53.     int count_0 = 0;
  54.  
  55.     while (count_0 != _n - 1){
  56.         x = make_offer(global_i);
  57.         if (x == 0){
  58.             count_0++;
  59.             global_i = count_0 + 1;
  60.         }
  61.         else global_i = x;
  62.     }
  63.  
  64.     std::cout<<"M - F"<<std::endl; // Male and Female (we had problems with russian localization)
  65.  
  66.     for (int i = 1; i < _n; i++)
  67.         std::cout<<i<<" - "<<mass_offer[i]<<std::endl;
  68.  
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement