Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4493
Problem Descriptionlilin was a student of Tonghua Normal University. She is studying at University of Chicago now. Besides studying, she worked as a tutor teaching Chinese to Americans. So, she can earn some money per month. At the end of the year, Lilin wants to know he average monthly money to decide whether continue or not. But she isn't good at calculation, so she's ask for your help. Lilin to calculate the average money and her earned per month.
Inputthe first line contain one integer T, means the total number of cases.
Every case would be twelve lines. Each line would contain the money she earned per month. Each number is positive and displayed to the penny. No dollar sign would be included.
Outputthe output is a single number and the average of money she earned for the twelve months. It'll be rounded to the nearest penny, preceded immediately by a dollar sign without tail zero. There'll be is no other spaces or characters in the output.
Sample Input
2 100.00 489.12 12454.12 1234.10 823.05 109.20 5.27 1542.25 839.18 83.99 1295.01 1.75100.00 100.00 100.00 100.00 100.00 10 0.00 100.00 100.00 100.00 100.00 100.00 100.00
Sample Output
1581.42100
Source2013 ACM-ICPC Jilin Tonghua National Invitational--title reappearance
The code is as follows:
#include <cstdio> #include <cstring>int main () { int t; scanf ("%d", &t); while (t--) { Double A, sum, ans; sum = 0; for (int i = 1; i <=; i++) { scanf ("%lf", &a); sum + = A; } ans = sum/12.0; int tt1 = ans*1000; int tt2 = ans*100; if (tt1%10 >= 5)//rounding { tt2+=1; } if (tt2%100 = = 0)//two X 0 { printf ("$%.0lf\n", ans); } else if (tt2%10 = = 0)//a 0 { printf ("$%.1lf\n", ans); } else { printf ("$%.2lf\n", ans); } } return 0;} /*101.5551.5551.5551.5551.5551.5551.5551.5551.5551.5551.5551.555*/
HDU 4493 Tutor (math AH)