-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path10114.cpp
More file actions
35 lines (30 loc) · 1.02 KB
/
10114.cpp
File metadata and controls
35 lines (30 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <cstring>
using namespace std;
int duration, n, m;
double total_loan, down_pay, dep[101], car_value, d;
/**
* It is entirely unclear from the problem statement how the depreciation is calculated and
* how it is applied to the price of the car. Moreover, it is unclear that one of the values coming
* in is the down payment, rather than the monthly payment for the car. After this is cleared,
* the problem is quite simple and easy.
*/
int main() {
while (cin >> duration >> down_pay >> total_loan >> n and duration > 0) {
for (int i = 0; i < n; i++) {
cin >> m >> d;
for (int j = m; j < 101; j++) dep[j] = d;
}
double monthly_pay = total_loan / duration;
car_value = (total_loan + down_pay) * (1 - dep[0]);
int month = 0;
while (total_loan > car_value) {
month++;
total_loan -= monthly_pay;
car_value *= 1 - dep[month];
}
if (month == 1) cout << month << " month" << endl;
else cout << month << " months" << endl;
}
return 0;
}