Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- const int n = 3; //Input matrix size (n x n)
- const int _n = n + 1;
- int global_i = 1;
- int mass_index[_n], mass_offer[_n];
- int massA[_n][_n], massB[_n][_n];
- int make_offer(int count){
- int offer;
- offer = massA[count][mass_index[count]];
- if (mass_offer[offer] == -1) {
- mass_offer[offer] = count;
- return 0;
- }
- else {
- for (int i = 1;i < _n; i++) {
- if ((massB[offer][i] == mass_offer[offer]) || (massB[offer][i] == count))
- if (massB[offer][i] == mass_offer[offer]) {
- mass_index[count]++;
- return count;
- }
- else {
- int x = mass_offer[offer];
- mass_index[mass_offer[offer]]++;
- mass_offer[offer] = count;
- return x;
- }
- }
- }
- }
- int main(){
- for (int i = 1; i < _n; i++){
- mass_index[i] = 1;
- mass_offer[i] = -1;
- }
- for (int i = 1; i < _n; i++)
- for (int j = 1; j < _n; j++)
- std::cin>>massA[i][j];
- for (int i = 1; i < _n; i++)
- for (int j = 1; j < _n; j++)
- std::cin>>massB[i][j];
- int x;
- int count_0 = 0;
- while (count_0 != _n - 1){
- x = make_offer(global_i);
- if (x == 0){
- count_0++;
- global_i = count_0 + 1;
- }
- else global_i = x;
- }
- std::cout<<"M - F"<<std::endl; // Male and Female (we had problems with russian localization)
- for (int i = 1; i < _n; i++)
- std::cout<<i<<" - "<<mass_offer[i]<<std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement