题目有点坑,收入是年初更新、房价是年尾更新
#include<iostream> using namespace std; int TryBuy(int n,int k){ float price = 200; float income = n; float money = 0; for(int i=1;i<=21;i++){ money+=income; if(money>=price) return i; price*=(1+(float)k/100); } return 0; } int main(){ int n,k; while(cin>>n>>k){ int year = TryBuy(n,k); if(year>0){ cout<<year<<endl; } else { cout<<"Impossible"<<endl; } } return 0; }