C++ 代码
用结构体存所有信息,由于是最前面的匹配对应的异性性别最后面的再开2个数组存男生女生信息
#include<iostream>
using namespace std;
const int N=60;
struct human{
int sex;
string name;
}h[N];
int n,x,y;
string man[N],woman[N];
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
int a;
string s;
cin>>a>>s;
h[i]={a,s};
if(a==0)woman[x++]=s;
else man[y++]=s;
}
for(int i=0;i<n/2;i++)
{
if(h[i].sex==0)
cout<<h[i].name<<" "<<man[--y]<<endl;
else
cout<<h[i].name<<" "<<woman[--x]<<endl;
}
return 0;
}