UVa 10793 - Foreign Exchange

来源:互联网 发布:虚拟股票交易源码 编辑:程序博客网 时间:2024/06/06 00:21

题目链接:UVa 10793 Foreign Exchange

这题目方法很多,也比较简单,使用vector练习一下STL。

#include <iostream>#include <vector>#include <algorithm>using namespace std;const int max_size = 50000;vector <int> map[max_size+5];int n,a,b,judge;int main(){    while(cin>>n && n != 0)    {        judge = 0;        for(int i = 0;i < n;i++)        {            cin>>a>>b;            if(find(map[b].begin(),map[b].end(),a) != map[b].end())            {                judge--;                map[b].erase(find(map[b].begin(),map[b].end(),a));            }            else            {                judge++;                map[a].push_back(b);            }        }        if(judge == 0)            cout<<"YES"<<endl;        else            cout<<"NO"<<endl;    }    return 0;}


0 0
原创粉丝点击