A - Financial Management C - Bank Interest

版权声明:文章全是博主转载, 请随意操作。 https://blog.csdn.net/ggqinglfu/article/details/82148526

A - Financial Management

 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.

 Input

The input 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.

Output

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.

 Sample Input

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

$1581.42

Tip1:

cout<<fixed<<setprecision(2); 在 #include <iomanip> 下, 是用来格式化输出(cout)的。其中(2)表示小数点后保留两位小数。

Tip2: 这是原作者整理的知识点链接: 

C / C++ 保留两位小数(setprecision(n)的一些用法总结) 

扫描二维码关注公众号,回复: 2988199 查看本文章
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iomanip>
using namespace std;
#define INF 0x3f3f3f3f

int main()
{
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(2);
    double a, sum;
    sum = 0;
    for(int i = 0; i < 12; i++)
    {
        cin >> a;
        sum += a;
    }
    cout << "$" << sum / 12 << endl;
    return 0;
}

C - Bank Interest

Farmer John made a profit last year! He would like to invest it well but wonders how much money he will make. He knows the interest rate R (an integer between 0 and 20) that is compounded annually at his bank. He has an integer amount of money M in the range 100..1,000,000. He knows how many years Y (range: 0..400) he intends to invest the money in the bank. Help him learn how much money he will have in the future by compounding the interest for each year he saves. Print an integer answer without rounding. Answers for the test data are guaranteed to fit into a signed 32 bit integer.

Input

* Line 1: Three space-separated integers: R, M, and Y

Output

* Line 1: A single integer that is the number of dollars FJ will have after Y years.

Sample Input

5 5000 4

Sample Output

6077

Hint

INPUT DETAILS: 

5% annual interest, 5000 money, 4 years 

OUTPUT DETAILS: 

Year 1: 1.05 * 5000 = 5250 
Year 2: 1.05 * 5250 = 5512.5 
Year 3: 1.05 * 5512.50 = 5788.125 
Year 4: 1.05 * 5788.125 = 6077.53125 
The integer part of 6077.53125 is 6077.

我水也就会发点水题, 不求来访, 但求一点积累的过程。嘿嘿 , 增加点文章数量嘛 

问题简述

       输入三个正整数R、M和Y,它们表示利率、存款余额和年数计算Y年后存款余额变为多少。要求输出结果为整数

问题分析

       这是一个单纯的计算问题,由于C语言库math.h中,有指数函数pow可以用于计算xy,使用该函数就可以简单地计算出结果。

但是显得low。好吧,我承认就是赚积分的。

 我转载一下原作者的分析, 我承认我也是赚积分的。

Tip1: cout << (int)money << endl;  这里输出要强转int, 不然可能会带小数。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iomanip>
using namespace std;
#define INF 0x3f3f3f3f

/*void hanno(int n, char a, char b, char c)
{
    if(n > 0)
    {
        hanno(n-1, a, c, b);
        cout << n << ":" << a << "->" << c << endl;
        hanno(n-1, b, a, c);
    }
}*/

int main()
{
    ios::sync_with_stdio(0);
   // cout<<fixed<<setprecision(0);
   int years;
   double rate, money;
   cin >> rate >> money >> years;
   for(int i = 0; i < years; i++)
   {
       money += money *(rate / 100);
   }

   cout << (int)money << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ggqinglfu/article/details/82148526
今日推荐