CSP-202212-1-现值计算
解题代码
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n;
double k, sumPrice = 0;
cin >> n >> k;
vector<double>priceList(n + 1);
for (int i = 0; i <= n; i++)
{
cin >> priceList[i];
}
for (int i = n; i >= 0; i--)
{
sumPrice += priceList[i] / pow(1 + k, i);
}
cout << sumPrice;
return 0;
}