题解 | 买房子

买房子

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int earnMoney = in.nextInt();
            int increase = in.nextInt();

            double price = 200.0;
            int year = 0;
            for(year = 1;year<=21;year++){
                //System.out.println("当前money:"+earnMoney * year+",当前price:"+price);
                if(earnMoney * year >= price){
                    break;
                }else{
                    double multiply = (increase * 1.0)/100 + 1;
                    price = price * multiply;
                }
            }
            System.out.println(year <= 21 ? year : "Impossible");
        }
        in.close();
    }
}

全部评论

相关推荐

没有奇迹的世界:简直世另我 一样的先学后端再转前端一样的简历模板 绷不住了甚至描述都这么像 值得庆幸的是你才28届 加油
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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