2014/02/25

[UVa] 10763 Foreign Exchange

Note:
     用到qsort然後兩兩對消


http://uva.onlinejudge.org/external/107/10763.html
#include<stdio.h>
#include <stdlib.h>

int cmp(const void *s1,const void *s2){
    return *(int*)s1-*(int*)s2;
}

int main(void){
    int n,i,count;
    while (scanf("%d",&n)!=EOF && n) {
        count = 0;
        int array[2*n];
        for (i = 0;i < 2*n;i++)
            scanf("%d",&array[i]);
        qsort(array, 2*n, sizeof(int), cmp);
        for (i = 0; i < 2*n; i+=2) {
            if (array[i]!=array[i+1])
                count++;
        }
        if (count==0)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}