博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2390 Bank Interest(我的水题之路——double和floa计算差别)
阅读量:4069 次
发布时间:2019-05-25

本文共 1817 字,大约阅读时间需要 6 分钟。

Bank Interest
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 11864   Accepted: 7071

Description

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.

Source

对于R%的年利率,本金为M,一共存Y年,问Y年之后本金+利润一共多少钱?
模拟。
注意点:
1)如果用double,中间值value变化情况如下(除了输出样例意外的输出,见解题代码的注释部分):
5 5000 4
1 5250.000000
2 5512.500000
3 5788.125000
4 6077.531250
6077
2)如果用float,中间值value变化情况如下:
5 5000 4
1 5250.000000
2 5512.499512
3 5788.124023
4 6077.529785
6077
如上,在比较小的数的计算的时候,用double计算更为精确。
代码(1AC):
#include 
#include
int main(void){ int r, m, y; int i; double value, rate; while (scanf("%d%d%d", &r, &m , &y) != EOF){ rate = 1 + (double)r / 100.0; value = m; for (i = 0; i < y; i++){ value *= rate; //printf("%d %lf\n", i + 1, value); } printf("%d\n", (int)value); } return 0;}

转载地址:http://nooji.baihongyu.com/

你可能感兴趣的文章
媒体广告业如何运用云盘提升效率
查看>>
企业如何运用企业云盘进行数字化转型-实现新发展
查看>>
司法如何运用电子智能化加快现代化建设
查看>>
iSecret&nbsp;1.1&nbsp;正在审核中
查看>>
IOS开发的开源库
查看>>
IOS开发的开源库
查看>>
Jenkins - sonarqube 代码审查
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成(一)
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成 - 单机部署(二)
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成 - 高可用集群部署(三)
查看>>
Golang struct 指针引用用法(声明入门篇)
查看>>
Linux 粘滞位 suid sgid
查看>>
C#控件集DotNetBar安装及破解
查看>>
Winform皮肤控件IrisSkin4.dll使用
查看>>
Winform多线程
查看>>
C# 托管与非托管
查看>>
Node.js中的事件驱动编程详解
查看>>
mongodb 命令
查看>>
MongoDB基本使用
查看>>
mongodb管理与安全认证
查看>>