OpenJudge exercises (C ++) -- question 4022: buy a house
Question:
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
A programmer started to work with an annual salary of N thousand yuan. He hopes to buy a 60-square-meter house in the village mansion. The current price is 2 million. Suppose the price of the house increases by K per year, in addition, the programmer's annual salary will remain unchanged in the future, does not eat or drink, and does not need to pay taxes. Every year, he will accumulate his income and ask if he can buy the house in the first few years? (The annual salary for the first year is 2 million RMB, and the house price is RMB)
-
Input
-
A row contains two positive integers, N (10 <= N <= 50) and K (1 <= K <= 20), separated by a single space.
-
Output
-
If you can buy this house in 20th years or before, an integer M is output, indicating that you can buy the house in the first M years. Otherwise, Impossible is output.
-
Sample Input
-
50 10
-
Sample output
-
8
Solution:
#include<iostream>using namespace std;int main(){double n;double k;while(cin>>n>>k){double y=1;double M=200;double All=n;while(true){All+=n;M*=(1+k/100);if(All>M){cout<<y+1<<endl; y="">19){cout<<"Impossible"<<endl; return="" pre=""><p></p> </endl;></y+1<<endl;></iostream>