ACM-HDoj暑假竞赛(7)-1009解题报告(

新浪博客 发表时间 -- 2009-07-27 16:38:21)

 

题目:

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
Outp:
      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
算法:
          虽然说英文不太懂,但一看到这个题目就大致猜到题意了,输入的数据是本金,利率,和最终所得的金额,求的是经过多少年能达到总金额,也就是第三个数.这应该是道很简单的初中数学题,幸好,还记得那个公式,一想到这就有点兴奋了,赶紧奋笔疾书...额,想想...P=(1+r%)^N*S...
P为总金额,r为每年的利润率,S为本金..有这公式就好办了...
代码:
        #include "stdio.h"
    #include "math.h"
int main()
{
  int year;
  float initial,rate,value,t,rate1;
  while (scanf("%f %f %f",&initial,&rate,&value)!=EOF)
  {
    year=0;
    rate1=rate/100;
    t=value/initial;
    year=log10(t)/log10(1+rate1);
    printf("%d\n",year+1);
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值