OpenJudge exercises (C ++) -- question 4022: buy a house

Source: Internet
Author: User

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&#43;1<<endl; y="">19){cout<<"Impossible"<<endl; return="" pre=""><p></p>   </endl;></y&#43;1<<endl;></iostream>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.