|
|
back to boardWhy WA#5? Posted by ScaV 29 Aug 2011 17:56 #include <stdio.h> #include <stdlib.h> #include <math.h> int cmp(const void *a, const void *b); int main() { long num,i; double k=0,*ms; scanf("%ld",&num); ms = (double*)malloc(num*sizeof(double)); for(i=0; i<num; i++) scanf("%lf",&ms[i]); qsort(ms,num,sizeof(double),cmp); for(i=0; i<num; i++){ k -= ms[i]; if(k<0) k=-k; } printf("%.0lf",k); return 0; } int cmp(const void *a, const void *b) { return -(*(double*)a-*(double*)b); } Edited by author 29.08.2011 22:27 |
|
|