Advertisement
otot957

Untitled

Aug 12th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include<array>
  3. #include <bits/stdc++.h>
  4. #include<string>
  5. using namespace std;
  6. int main ()
  7.  
  8.  
  9.  
  10. {
  11.     int mon, nperiod,m,n=0;
  12.     double down, loan,dp,dps[101],val,lperm;
  13.  
  14.     while(true){
  15.             n=0;
  16.         cin>>mon>>down>>loan>>nperiod;
  17.         if(mon<0)
  18.             break;
  19.         for (int i=0;i<nperiod;i++){
  20.             cin>>m>>dp;
  21.             for(int j=m;j<101;j++)
  22.                 dps[j]=dp;
  23.         }
  24.         lperm=loan/mon;
  25.         val=(loan+down);
  26.         val-=val*dps[0];
  27.         while(val<loan)
  28.         {
  29.             n++;
  30.             loan-=lperm;
  31.             val-=val*dps[n];
  32.         }
  33.         if(n==1)
  34.             cout<<n<<" month"<<endl;
  35.         else cout<<n<<" months"<<endl;
  36.     }
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement