1 条题解
-
0
#include <iostream> #include <vector> using namespace std; struct Depreciation { int month; double rate; }; int main() { while (true) { int duration, records; double down_payment, loan_amount; cin >> duration; if (duration < 0) break; cin >> down_payment >> loan_amount >> records; vector<double> rates(duration + 1); for (int i = 0; i < records; ++i) { int m; double r; cin >> m >> r; rates[m] = r; } // Fill in missing months with last known rate for (int i = 1; i <= duration; ++i) { if (rates[i] == 0) rates[i] = rates[i - 1]; } double car_value = loan_amount + down_payment; double owed = loan_amount; double monthly_payment = loan_amount / duration; car_value *= (1 - rates[0]); int month = 0; while (owed >= car_value) { month++; owed -= monthly_payment; car_value *= (1 - rates[month]); } cout << month << " month"; if (month != 1) cout << "s"; cout << endl; } return 0; }
- 1
信息
- ID
- 572
- 时间
- 1000ms
- 内存
- 10MiB
- 难度
- 5
- 标签
- 递交数
- 1
- 已通过
- 1
- 上传者