题解 | #买房子#

买房子

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

#include <stdio.h>

int main() {
    int n, k;
    while (scanf("%d %d", &n, &k) != EOF) {
        int year = 1;
        double price = 200;
        double money = 0;
        while (year < 22) {
            money += n;
            if (money >= price) {
                break;
            }
            price = price * (1 + k / 100.0);// 此处100.0非常重要
            // 如果是100的话就会出错,必须转为浮点型
            year++;
        }
        if (year == 22) {
            printf("Impossible\n");
        } else {
            printf("%d\n", year);
        }
    }
    return 0;
}

全部评论

相关推荐

头像
不愿透露姓名的神秘牛友
04-29 12:10
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务