题解 | 买房子

买房子

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

#include <iostream>
using namespace std;

int main() {
    int n;
    double k;
    while (cin >> n >> k) {
        int price = 200;
        int salary = 0;
        bool afford = false;
        for (int i = 1; i <= 21; i++) {
            salary += n;
            if (salary >= price) {
                afford = true;
                cout << i << endl;
                break;
            }
            price = 1.0 * price * (1+ k / 100);
            
        }
        if (!afford)cout << "Impossible" << endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 11:30
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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