#include<map>
#include<iostream>
using namespace std;
int main()
{
int n, A, B;
map<int, int> partner;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> A >> B;
partner[A] = B;
}//信息录入完毕
map<int, int>::iterator it = partner.begin();
for (; it != partner.end(); it++)
{
int temp_first = it->first;
int temp_second = it->second;
map<int, int>::iterator pos = partner.find(temp_second);
if (pos != partner.end())
{
if(pos->second == temp_first){}
else {
cout << "无法成功配对。\n";
return 0;
}
}
else {
cout << "无法成功配对。\n";
return 0;
}
}
cout << "配对成功\n";
return 0;
}
《算法经典》UVa10763--交换学生--个人题解代码
最新推荐文章于 2024-11-12 12:29:51 发布