码迷,mamicode.com
首页 > 其他好文 > 详细

UVa 10763 - Foreign Exchange

时间:2014-12-27 08:59:41      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

统计国家代号出现的次数,如果去的和来的相等就输出YES即可。

import java.util.*;

public class Main10763 {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while(true) {
			int n = scan.nextInt();
			if(n == 0) break;
			int[] a = new int[500000], b = new int[500000];
			Arrays.fill(a, 0);
			Arrays.fill(b, 0);
			int maxg = 0;
			for(int i=0; i<n; i++) {
				int mm = scan.nextInt();
				int nn = scan.nextInt();
				maxg = max(maxg, max(mm, nn));
				a[mm] ++;
				b[nn] ++;
			}
			int cnt = 0;
			for(int i=0; i<=maxg; i++) {
				if(a[i] != b[i]) {
					cnt = 1;
					break;
				}
			}
			if(cnt == 0)
				System.out.println("YES");
			else
				System.out.println("NO");
				
			
		}

	}
	public static int max(int a, int b) {
		if(a >= b)
			return a;
		else
			return b;
	}

}


 

UVa 10763 - Foreign Exchange

标签:

原文地址:http://blog.csdn.net/wxisme/article/details/42178277

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!