poj 2390 Bank Interest(计算本利和)
生活随笔
收集整理的這篇文章主要介紹了
poj 2390 Bank Interest(计算本利和)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、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 YOutput
* Line 1: A single integer that is the number of dollars FJ will have after Y years.二、題解
?????? 題目的提示很明顯,計算過程如下:
?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.
???? 需要注意的是計算過程中間結果要用double存放。
三、java代碼
import java.util.Scanner;public class Main {public static void main(String[] args) { Scanner sc = new Scanner(System.in);int r,m,y,i;double result,r1;r=sc.nextInt();m=sc.nextInt();y=sc.nextInt();r1=0.01 * r+1;result=m;for(i=0;i<y;i++){result*=r1;}System.out.println((int)result);} }
版權聲明:本文為博主原創文章,未經博主允許不得轉載。
轉載于:https://www.cnblogs.com/AndyDai/p/4734141.html
總結
以上是生活随笔為你收集整理的poj 2390 Bank Interest(计算本利和)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2019牛客多校第七场E Find th
- 下一篇: mongodb数据库的备份与恢复