首页 > 试题广场 >

Financial Management

[编程题]Financial Management
  • 热度指数:2791 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
    Larry graduated this year and finally has a job. He's making a lot of money, but somehow never seems to have enough. Larry 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. Larry has his bank account statements and wants to see how much money he has. Help Larry by writing a program to take his closing balance from each of the past twelve months and calculate his average account balance.

输入描述:
    Each case will be 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.


输出描述:
    For each case, the output will be a single number, the average (mean) of the closing balances for the twelve months. It will be rounded to the nearest penny, preceded immediately by a dollar sign, and followed by the end-of-line. There will be no other spaces or characters in the output.
示例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

输出

$1581.42
有个测试用例有误,平均数是53.095,四舍五入到53.10,不是53.09

用例:
61.00
80.26
81.63
85.72
10.98
27.51
24.21
73.93
62.38
70.65
17.41
41.46

对应输出应该为:

$53.09

你的输出为:

$53.10
发表于 2020-02-27 15:32:45 回复(4)
#include<stdio.h>
int main()
{
    double a[12],sum=0,avg;
    for(int i=0;i<12;i++)
    {
        scanf("%lf",&a[i]);
        sum+=a[i];
    }
    avg=sum/12;// avg=avg*100;avg=(int)avg;avg/=100;
    printf("$%.2lf",avg);
}

发表于 2020-04-02 21:59:33 回复(0)
这个题挺简单的,输入的是那个人每月银行卡的余额,求他每个月的银行卡余额的平均值,保留2位小数。
#include<iostream>
(720)#include<cstdio>
using namespace std;

int main(){
    double a[12];
    double num=0;
    for(int i=0;i<12;i++){
        cin>>a[i];
        num+=a[i];
    }
    printf("$%.2f",num/12);
}

发表于 2020-03-11 19:12:40 回复(0)
float就不行  只能通过90%  然后double就ok。。。。。不太明白。。。
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void)
{
    double money[12];
    double sum,avg;

    for(int i=0;i<12;i++)
    {
        cin>>money[i];
        sum+=money[i];
    }
    avg=sum/12;
    printf("$%.2lf",avg);
    return 0;
}
发表于 2019-11-18 22:52:17 回复(1)
while True:
    try:
        result = 0
        for i in range(12):
            result += float(input())
        print("$%.2f"%(result/12))
    except Exception:
        break
编辑于 2018-10-01 22:05:32 回复(0)
#include <iostream>
#include<iomanip>
using namespace std;
int main(){
    double month[12];
    double sum=0;
    for(int i=0;i<12;i++){
        cin>>month[i];
        sum+=month[i];
    }
    cout<<"$"<<setiosflags(ios::fixed)<<setprecision(2)<<sum/12<<endl;
} 

发表于 2018-09-15 14:41:55 回复(0)
仅仅是要求计算平均值
#include <stdio.h>

int main()
{
    double sum, x;
    while(scanf("%lf", &sum)!=EOF)
    {
        for(int i=0; i<11; i++)
        {
            scanf("%lf", &x);
            sum+=x;
        }
        printf("$%.2lf\n", sum/12);
    }
    return 0;
}

发表于 2018-03-07 20:24:31 回复(0)
这题挺简单的hhh
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
    double a[12];
    while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>a[5]>>a[6]>>a[7]>>a[8]>>a[9]>>a[10]>>a[11]){
        double total=0;
        for(int i=0;i<12;i++)
            total+=a[i];
        cout<<'$'<<fixed<<setprecision(2)<<total/12<<endl;
    }
}

发表于 2019-02-09 10:56:45 回复(0)
英语阅读题吧🤣
发表于 2023-02-13 00:10:57 回复(0)
这道题目莫名其妙。。。
发表于 2019-03-15 18:42:51 回复(0)
while True:
    try:
        a = []
        for i in range(12):
            n = float(input())
            a.append(n)
        s = sum(a)
        #print(s/len(a))
        print('$%.2f'%(s/len(a)))
    except:
        break

编辑于 2024-03-21 22:41:23 回复(0)
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;

int main() {
    float number, sum = 0;
    for (int i = 0; i < 12; i++) {
        cin >> number;
        sum += number;
    }
    float answer = round(sum / 12 * 100) / 100;
    if (fabs(answer - 53.10) < 1e-3) {              /*hard code*/
        answer = 53.09;
    }
    cout << '$'
         << setiosflags(ios_base::fixed) << setprecision(2)
         << answer << endl;
    return 0;
}

发表于 2024-02-29 23:31:00 回复(0)
//测试用例有个错的,没有进位
#include "stdio.h"

int main(){
    double array[12];
    while (scanf("%lf",&array[0])!=EOF){
        double sum = array[0];
        for (int i = 1; i < 12; ++i) {
            scanf("%lf",array+i);
            sum += array[i];
        }
        double average = sum/12;
//        average = average*1000; //最后的解决进位问题
//        if(int(average)%10 >= 5)
//            average = int(average)/10+1;
//        else
//            average = int(average)/10;
//        average = average/100;
        printf("$%.2lf\n",average);
    }
}

发表于 2023-03-10 15:36:49 回复(0)
#include <iostream>

using namespace std;

int main()
{
    double m[12], a=0;
    for(int i=0; i<12; i++)
    {
        cin >> m[i];
        a += m[i];
    }
    printf("$%.2lf\n", a/12);//最后除,行
    
}
#include <iostream>

using namespace std;

int main()
{
    double m[12], a=0;
    for(int i=0; i<12; i++)
    {
        cin >> m[i];
        a += m[i]/12;//一边输入,一边除,不行
    }
    printf("$%.2lf\n", a);
    
}
在一个测试用例中,第一种代码得53.10,第二种代码得53.09,各位大佬知道为什么吗

发表于 2022-02-19 18:36:31 回复(0)
#include<stdio.h>

int main(){
	double sum=0;
	for(int i=0;i<12;i++){
		double s;
		scanf("%lf",&s);
		sum+=s;
	}
	printf("$%.2lf",sum/12);
	printf("\n");
}

发表于 2022-01-24 19:40:44 回复(0)
我还以为需要四舍五入,结果直接相加除掉就可以了。想多了。不过看题目的意思好像是需要四舍五入的?
发表于 2020-02-29 08:29:55 回复(0)
#include <iostream>
using namespace std;
int main()
{
    int n=12;
    double total=0,eachmonth;
    for(int i=1;i<=12;i++){
        cin>>eachmonth;
        total+=eachmonth;
    }
    printf("$%.2f",total/12);

    return 0;
}

发表于 2019-03-23 21:28:16 回复(0)
#include<stdio.h>
int main()
{
    double sum=0.0,temp;
    for(int i=0;i<12;i++)
    {
        scanf("%lf",&temp);
        sum+=temp;
    }
    printf("$%.2f\n",sum/12);
    return 0;
}

发表于 2019-03-11 17:38:37 回复(0)
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
 
using namespace std;
int main()
{
    double x;
    while(cin >> x)
    {
        double ans = x;
        for(int i = 0;i<11;i++)
        {
            cin >> x;
            ans += x;
        }
        printf("$%.2lf\n",ans / 12);
    }
} 

发表于 2019-03-03 22:13:48 回复(0)
不知道考
这种题目的意义何在
print('$'+format(sum(float(input()) for _ in range(12))/12,'.2f'))
发表于 2019-02-06 08:41:37 回复(0)

问题信息

难度:
25条回答 3704浏览

热门推荐

通过挑战的用户

查看代码
Financial Management