admin管理员组文章数量:1558055
Suppose you open a savings account with a certain initial balance. You will not make any withdrawals or further deposits for a number of years. The bank will compound your balance (add the annual interest) once a year, on the anniversary of the opening of the account. Your goal is to achieve a certain target amount in your savings account. In how may years will the target amount be achieved?
Input
The input file will contain data for one or more test cases, one test case per line. Each line will contain three numbers: the initial balance, the annual interest rate (as a percentage of the balance), and the target amount, separated by blank spaces. These will be positive numbers; they may or may not contain a decimal point. The target amount will be greater than the initial balance. The input is terminated by end-of-file
Output
For each line of input, your program will produce exactly one line of output: This line will contain one positive integer value: the number of years required to achieve the target amount.
Sample Input
200.00 6.5 300
500 4 1000.00
Sample Output
7
18
就是银行的存款机制,水题一发,但是注意精度问题。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
double n,p,m;
int main()
{
while(scanf("%lf%lf%lf",&n,&p,&m)!=EOF)
{
int cnt=0;
while(n<m)
{
n=(1+p/100)*n;
cnt++;
}
printf("%d\n",cnt);
}
}
努力加油a啊,(o)/~
版权声明:本文标题:Savings Account(水题) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1727342754a1109606.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论