UVA 11945 Financial Management 水题

本博客指导您如何通过输入过去十二个月的银行结余,计算出平均银行余额,并注意在输出时正确使用逗号分隔千位。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Financial Management

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=20184

Description

Michael graduated of ITESO this year and finally has a job. He's making a lot of money, but somehow never seems to have enough. Michael has decided that he needs to grab hold of his financial portfolio and solve his financing problems. The first step is to figure out what's been going on with his money.

Michael has his bank account statements and wants to see how much money he has. Help Michael by writing a program to take his closing balance from each of the past twelve months and calculate his average account balance.

Input

The first line of input contains a single integer N, ( 1$ \le$N$ \le$100) which is the number of datasets that follow.

Each dataset consists of twelve lines. Each line will contain the closing balance of his bank account for a particular month. Each number will be positive and displayed to the penny. No dollar sign will be included.


Output

For each dataset, you should generate one line of output with the following values: The dataset number as a decimal integer (start counting at one), a space, a character `$', and a single number, the average (mean) of the closing balances for the twelve months. It will be rounded to the nearest penny.


Note: Used comma (,) to separate 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 Output

1 $1,581.42

HINT

题意

 

        啊,给你十二个月的钱,然后求平均钱数,注意在千位打逗号

 

题解:

 

  加起来除以12咯

 

代码:

 

//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>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff;   //无限大
const int inf=0x3f3f3f3f;
/*

*/
//**************************************************************************************
inline ll read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int buf[10];
inline void write(int i) {
  int p = 0;if(i == 0) p++;
  else while(i) {buf[p++] = i % 10;i /= 10;}
  for(int j = p-1; j >=0; j--) putchar('0' + buf[j]);
  printf("\n");
}
int main()
{
    int t=read();
    for(int cas=1;cas<=t;cas++)
    {
        double sum=0;
        double x=0;
        for(int i=0;i<12;i++)
        {
            cin>>x;
            sum+=x;
        }
        sum/=12;
        int a=(int)(sum/1000);
        sum-=a*1000;
        if(a>0)
            printf("%d $%d,%.2f\n",cas,a,sum);
        else
            printf("%d $%.2f\n",cas,sum);
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值