题解 | #买房子#

买房子

https://www.nowcoder.com/practice/a4b46b53773e4a8db60b5f7629ce03e9

#include <iostream>

using namespace std;
int main(){
    int n;
    double k;
    while (cin>>n>>k){
        int year = 1;
        int savings = n;
        double price = 200;
        while (savings<price){
            savings+=n;
            price*=(1+k/100);
            year++;
            if (year>21) break;//记得一定要加这一句,不然就无限循环了
        }
        if (year<=21){
            cout<<year<<endl;
        }
        else{
            cout<<"Impossible"<<endl;
        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务