UVa 10763 - Foreign Exchange
统计国家代号出现的次数,如果去的和来的相等就输出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;
}
}
作者:Pickle
声明:对于转载分享我是没有意见的,出于对博客园社区和作者的尊重一定要保留原文地址哈。
致读者:坚持写博客不容易,写高质量博客更难,我也在不断的学习和进步,希望和所有同路人一道用技术来改变生活。觉得有点用就点个赞哈。








浙公网安备 33010602011771号