UVA-10763 Foreign Exchange

Vjudge题目链接,STL的map,我上来就set写了一个,wa了才发现每组有重复输入的,所以set不行。

#include<cstdio>
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;

int main(){
    int n;
    while(~scanf("%d", &n) && n){
        map<int, int> mp;
        int a1, a2;
        for(int i = 0; i < n; i++){scanf("%d %d", &a1, &a2); mp[a1]--; mp[a2]++;}
        bool ans = true;
        for(map<int,int>::iterator it = mp.begin(); it != mp.end(); it++){
            if((it->second) != 0){ans = false; break;}
        }
        if(ans)printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

UVA-10763 Foreign ExchangeUVA-10763 Foreign Exchange good vegetable 发布了21 篇原创文章 · 获赞 1 · 访问量 7461 私信 关注
上一篇:Borrowers UVA - 230


下一篇:UVa 11600 Masud Rana