[UVa] 10763 Foreign Exchange

Note:
     用到qsort然後兩兩對消

http://uva.onlinejudge.org/external/107/10763.html
#include
#include

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;
}

UVa 11462 Age Sort

Note:

Use qsort in
http://uva.onlinejudge.org/external/114/11462.html
#include
#include

int cmp(const void *s1, const void *s2);

int main(void){
int n = 0,i;
int array[2000005];
while (scanf("%d",&n)!=EOF && n!=0) {
for (i = 0; i < n; i++)
scanf
("%d",&array[i]);

qsort
(array, n, sizeof(int), cmp);
printf
("%d",array[0]);
for (i = 1; i < n; i++) {
printf
(" %d",array[i]);
}
printf
("\n");
}

return 0;
}

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

UVa 494 Kindergarten Counting Game

http://acm.cs.nthu.edu.tw/problem.php?pid=7073
#include
#include

int main(void){
char string[10000];
int i, flag, count, k;
while(gets(string)!= NULL){
flag
= 0;
count
= 0;
k
= strlen(string);
for(i = 0; i < k;i++){
if(string[i]>=65 && string[i]<=90||string[i]>=97&&string[i]<=122)
flag
= 1;
else{
count
= count + flag;
flag
= 0;
}
}
count
= count + flag;/*判斷最後一個字*/
printf
("%d\n", count);
}
return 0;
}