forked from Diusrex/UVA-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10114 Loansome Car Buyer.cpp
56 lines (37 loc) · 1.44 KB
/
10114 Loansome Car Buyer.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <vector>
#include <cstdio>
using namespace std;
int main()
{
int monthNums, numDeprecations, currentDecrease, currentMonth;
double carTotal, downPayment, loanOwed, amountPayedPerMonth;
vector<int> decreaseTime;
vector<double> decrease;
scanf("%d", &monthNums);
while (monthNums > 0)
{
scanf("%lf %lf %d", &downPayment, &loanOwed, &numDeprecations);
amountPayedPerMonth = loanOwed / monthNums;
carTotal = downPayment + loanOwed;
decreaseTime.resize(numDeprecations + 1);
decrease.resize(numDeprecations + 1);
for (int i = 0; i < numDeprecations; ++i)
scanf("%d %lf", &decreaseTime[i], &decrease[i]);
decreaseTime[numDeprecations] = 101;
currentDecrease = 0;
carTotal -= carTotal * decrease[currentDecrease];
for (currentMonth = 1; carTotal < loanOwed; ++currentMonth)
{
loanOwed -= amountPayedPerMonth;
if (decreaseTime[currentDecrease + 1] == currentMonth)
++currentDecrease;
carTotal -= carTotal * decrease[currentDecrease];
}
--currentMonth;
if (currentMonth == 1)
printf("%d month\n", currentMonth);
else
printf("%d months\n", currentMonth);
scanf("%d", &monthNums);
}
}