题解 | #爬楼梯#
爬楼梯
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()); } }