有多行,每行两个整数N(10<=N<=50), K(1<=K<=20)
针对每组数据,如果在第21年或者之前就能买下这套房子,则输出一个整数M,表示最早需要在第M年能买下,否则输出Impossible,输出需要换行
50 10 40 10 40 8
8 Impossible 10
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int n, k, year; //n-年薪 k-房价涨幅 存款年数 while (scanf("%d %d", &n, &k) != EOF) { double total_save = n, value = 200; //value-房价 for (year = 1; total_save < value && n > value * k / 100.0 ; year++) { total_save += n; value *= (1.0 + k / 100.0); } if (total_save >= value) { printf("%d\n", year); } else { printf("Impossible\n"); } } }