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 |
ac 代码(本题关键是读懂题意)//down payment 是首付款 月供是指贷款总额/月数 #include<iostream> #include<string> #include<cmath> using namespace std; double toDouble(string rate) { double sum=0; for(int i=1;i<rate.length();i++) { sum+=(rate[i]-'0')*pow(0.1,i); } return sum; } double mon_rate[105]; int main() { int month,depress,i,j,start; double month_pay,sum; string rate; while(scanf("%d%lf%lf%d",&month,&month_pay,&sum,&depress)!=EOF) { memset(mon_rate,0,sizeof(mon_rate)); if(month<0) break; else { for(i=0;i<depress;i++) { cin>>start>>rate; double rate_double=toDouble(rate); mon_rate[start]=rate_double; } double pre; for(i=0;i<=month;i++) { if(fabs(mon_rate[i])<0.0000000001) mon_rate[i]=pre; else pre=mon_rate[i]; } double car_value,owe_money; double each_month; owe_money=sum; car_value=(sum+month_pay)*(1-mon_rate[0]); if(owe_money<car_value) printf("%d months\n",0); else { i=1; each_month=sum/month; while(1) { car_value=car_value*(1-mon_rate[i]); owe_money=owe_money-each_month; if(car_value>owe_money) break; i++; } if(i==1) printf("%d month\n",i); else printf("%d months\n",i); } } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator