2.每跑完一次,紀錄配對完的男女編號
3.在跑下一次時,剔除配對過的編號
#include<iostream>
using namespace std;
int main()
{
int n, x = 0, max = 0, count = 0, check = 0;
int arr[100][100], a[100], b[100];
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> arr[i][j];
while (count != n)
{
max = 0;
for (int i = 0; i < n; i++)
{
check = 0;
for (int j = 0; j < x; j++)
if (i == a[j])
{
check = 1;
break;
}
if (check == 0)
{
for (int j = 0; j < n; j++)
{
check = 0;
for (int k = 0; k < x; k++)
if (j == b[k])
{
check = 1;
break;
}
if (check == 0 && arr[i][j] > max)
{
max = arr[i][j];
a[x] = i;
b[x] = j;
}
}
}
}
count++;
x++;
}
for (int k = 0; k < x; k++)
cout << "boy " << a[k] + 1 << " pair with girl " << b[k] + 1 << endl;
return 0;
}
沒有留言:
張貼留言