Advertisement
Plabon_dutta

UVA 10114 - Loansome Car Buyer

Mar 26th, 2021
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int loanDur, nRec;
  7.     double downPayment, loan, decP[101];
  8.  
  9.     while (true) {
  10.         cin >> loanDur >> downPayment >> loan >> nRec;
  11.         if (loanDur < 0)
  12.             break;
  13.  
  14.         int m;
  15.         double p;
  16.         while (nRec--) {
  17.             cin >> m >> p;
  18.             for (int i = m; i < 101; i++)
  19.                 decP[i] = p;
  20.         }
  21.  
  22.         int now = 0;
  23.         double monthlyPayment = loan / loanDur;
  24.         double curVal = (loan + downPayment) * (1 - decP[0]);
  25.         double curLoan = loan;
  26.         while (curVal < curLoan) {
  27.             now++;
  28.             curLoan -= monthlyPayment;
  29.             curVal = curVal * (1-decP[now]);
  30.         }
  31.  
  32.         cout << now << " month";
  33.         if (now != 1)
  34.             cout << "s";
  35.         cout << endl;
  36.     }
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement