题解 | #爬楼梯#

爬楼梯

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());
        }
    }
全部评论

相关推荐

墨西哥大灰狼:如果你的校友卤馆还在的话,他肯定会给你建议的,可是卤馆注销了@ 程序员卤馆
点赞 评论 收藏
分享
05-14 20:34
门头沟学院 Java
窝补药贝八股:管他们,乱说,反正又不去,直接说680
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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