题解 | #爬楼梯#

爬楼梯

http://www.nowcoder.com/practice/b178fcef3ed4448c99d7c0297312212d

这道题。。。就考个大小越界,int不行、long也不行。。。我去

public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String i = sc.nextLine();
            long num = Long.parseLong(i);
            if(num==1) {
                System.out.println(1);
                continue;
            }
            BigDecimal pre = new BigDecimal(1);
            BigDecimal curr = new BigDecimal(2);
            for (int j = 0; j < num-2; j++) {
                BigDecimal tem = curr;
                curr = curr.add(pre);
                pre = tem;
            }
            System.out.println(curr.toString());
        }
    }
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 17:58
点赞 评论 收藏
分享
VirtualBoo...:都去逗他了?
点赞 评论 收藏
分享
06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
实习吐槽大会
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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