题解 | #买房子#
买房子
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; }