A number of students is members of a club, travels annually to exotic locations. Their destinations in the past has included Indianapolis, Phoenix, Nashville, Philadelphia, San Jose, and Atlanta. This spring they is planning a trip to Eindhoven.
The group agrees in advance to share expenses equally, but it isn't practical to has them share every expense as it OCCU Rs. So individuals in the group pay for particular things, like meals, hotels, taxi rides, plane tickets, etc. After the trips, each student ' s expenses was tallied and money was exchanged so, the net cost to each of the same, to WI Thin one cent. In the past, this money exchange has been tedious and time consuming. Your job is-to-compute, from a list of expenses, the minimum amount of money, must change hands in order to equalize ( Within a cent) all the students ' costs.
Input
Standard input would contain the information for several trips. The information consists of a line containing a positive integer, n, and the number of students on the trip, fol Lowed by n lines of input, each containing the amount, in dollars and cents, spent by a student. There is no more than-students and no student spent more than $10,000.00. A single line containing 0 follows the information.
Output
For each trip, output a line stating the total amount of money, in dollars and cents, that must being exchanged to equalize T He students ' costs.
Sample Input
310.0020.0030.00415.0015.013.003.010
Sample Output
$10.00$11.99
Source: Waterloo Local Contest Jan, 1999
Some notes:
1.
2.
3.
4.
1 /*2 #include <stdio.h>3 #include <string.h>4 5 float cost[100];6 int cost100[100];7 8 void sort (int num);9 Ten int main (void) One { A int num,i,sum=0; - int avg,last; - int change_sum=0; the double change; - - scanf ("%d", &num); - While (num! = 0) { + For (i=0;i<num;i++) { - scanf ("%f", &cost[i]); + Cost100[i] = 100*cost[i] + 0.5; A sum + = Cost100[i]; at } - avg = sum/num; - Last = Sum%num; - sort (num); - For (i=0;i<num;i++) { - if (i<last) in Cost100[i] = cost100[i]-avg-1; - Else to Cost100[i] = cost100[i]-avg; + if (Cost100[i] > 0) - change_sum + = Cost100[i]; the } * $ Change = ((double) change_sum)/100;Panax Notoginseng printf ("$%.2f\n", change); - the memset (cost,0,num*sizeof (float)); + memset (cost100,0,num*sizeof (int)); A the sum = 0; + change_sum = 0; - $ scanf ("%d", &num); $ } - - //system ("PAUSE"); the return 0; - }Wuyi void sort (int num) the { - int i,j; Wu For (i=0;i<num;i++) { - For (j=0;j<num;j++) { About if (cost100[j]<cost100[j+1]) { $ int temp = cost100[j]; - Cost100[j] = cost100[j+1]; - cost100[j+1] = temp; - } A } + } the - } $ */ the the the#include <stdio.h> the #defineNum 1005 - DoubleS[num]; in intMain () the { the intN, T, I; About while(SCANF ("%d", &n) = =1&&N) the { the Doublesum =0, Resulth =0, RESULTL =0; the for(i =0; I < n; i++) + { -scanf"%LF", &s[i]); theSum + =S[i];Bayi } theSum/=N; the - for(i =0; I < n; i++) - if(S[i] <sum) the { theResultl + = (int) ((Sum-s[i]) * -) /100.0; the } the Else -Resulth + = (int) ((S[i]-sum) * -) /100.0; theprintf"$%0.2lf\n", Resultl < resulth?resulth:resultl); the } the return 0;94}
1301. The trip