| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么总是WA呢?不懂...#include<iostream>
using namespace std;
int main(){
int mon, dep_rec;
float down_pay, amount_of_loan, amount_of_car;
int total_months[50];
int flag = 0;
struct depreciation{
int month;
float dep;
};
do{
total_months[flag] = 0;
cin >> mon >> down_pay >> amount_of_loan >> dep_rec;
if(mon < 0 ) break;
depreciation *records = new depreciation[dep_rec];
for(int i = 0; i < dep_rec; i++)
cin >> records[i].month >> records[i].dep;
float month_pay = amount_of_loan / mon;
int n = 0;
amount_of_car = down_pay + amount_of_loan;
for(int j = 0; j < mon; j++){
if(total_months[flag] !=0)
amount_of_loan -= month_pay;
if(records[n].month == j && n < dep_rec){
amount_of_car = amount_of_car * (1 - records[n].dep);
n++;
}
else
amount_of_car = amount_of_car * (1 - records[n - 1].dep);
total_months[flag] += 1;
if(amount_of_loan < amount_of_car) break;
}
flag++;
}while(mon > 0);
for(int k = 0; k < 50 && total_months[k] > 0; k++){
if(total_months[k] == 2)
cout<< "1 month"<<endl;
else
cout<< total_months[k] - 1 <<" months"<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator