Financial Management
Time limit:1 Sec Memory limit:256 MB
Topic Connection
acm.hust.edu.cn/vjudge/problem/visitoriginurl.action?id=20184
Description
Michael graduated of Iteso this year and finally have a job. He's making a lot of money, but somehow never seems to has enough. Michael has decided the he needs to grab hold of his financial portfolio and solve his financing problems. The first step is to a figure out what's been going on with the he money.
Michael has the He bank account statements and wants to see how the much money he had. Help-Michael by writing-a program-to-take his-closing balance from each of the past twelve months and calculate his Averag E account balance.
Input
The first line of input contains a single integer n, ( 1N.) which is the number of datasets th at follow.
Each dataset consists of twelve lines. Each line would contain the closing balance of his bank account for a particular month. Each number is positive and displayed to the penny. No dollar sign would be included.
Output
For each dataset, you should generate one line of output with the following values:the dataset number as a decimal intege R (start counting at one), a space, a character '$', and a single number, the average (mean) of the closing Balan Ces for the twelve months. It'll be rounded to the nearest penny.
note:used comma (,) toseparate the thousands.
Sample Input
1 100.00 489.12 12454.12 1234.10 823.05 109.20 5.27 1542.25 839.18 83.99 1295.01 1.75
Sample OUTPUT1 $1,581.42
HINT
Test instructions
Ah, give you 12 months of money, and then ask for the average amount, pay attention to the comma in thousands
Exercises
and divide it by 12.
Code:
//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 200001#defineMoD 10007#defineEPS 1e-9//const int INF=0X7FFFFFFF; //infinitely LargeConst intinf=0x3f3f3f3f;/**///**************************************************************************************inline ll read () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}intbuf[Ten];inlinevoidWriteinti) {intp =0;if(i = =0) p++; Else while(i) {buf[p++] = i%Ten; I/=Ten;} for(intj = P1; J >=0; j--) Putchar ('0'+Buf[j]); printf ("\ n");}intMain () {intt=read (); for(intcas=1; cas<=t;cas++) { Doublesum=0; Doublex=0; for(intI=0;i< A; i++) {cin>>x; Sum+=x; } Sum/= A; intA= (int) (sum/ +); Sum-=a* +; if(a>0) printf ("%d $%d,%.2f\n", cas,a,sum); Elseprintf ("%d $%.2f\n", cas,sum); }}
UVA 11945 Financial Management water problem