首页 > 专题系列 > Java解POJ > POJ 2756 Autumn is a Genius [解题报告] Java
2013
11-11

POJ 2756 Autumn is a Genius [解题报告] Java

Autumn is a Genius

问题描述 :

Jiajia and Wind have a very cute daughter called Autumn. She is so clever that she can do integer additions when she was just 2 years old! Since a lot of people suspect that Autumn may make mistakes, please write a program to prove that Autumn is a real genius.

输入:

The first line contains a single integer T, the number of test cases. The following lines contain 2 integers A, B(A, B < 32768) each. The size of input will not exceed 50K.

输出:

The output should contain T lines, each with a single integer, representing the corresponding sum.

样例输入:

1
1 2

样例输出:

3

温馨提示:

There may be ‘+’ before the non-negative number!

解题代码:

import java.util.*;  
    import java.math.*;  
      
    public class Main {  
      
        public static void main(String[] args)   
        {  
            Scanner cin = new Scanner(System.in);  
            int num = Integer.valueOf(cin.nextLine()).intValue();  
             
           for(int i = 0; i < num; i++)  
           {  
               String[] str = cin.nextLine().split(" ");  
     
               BigDecimal a = new BigDecimal(str[0]);  
               BigDecimal b = new BigDecimal(str[1]);  
                 
               BigDecimal result = a.add(b);  
               System.out.println(result.toPlainString());  
          }  
     
       }  
     
   }

  1. 我等到老了,颤抖着嘴唇对自己的孙子说:孩子……等……偷星九月天全集出来了,一定……要把…… 书烧……给我,我要在下面看。 孩子说:放心吧爷爷,我一定努力活到那一天。听完孙子的话爷爷满意 的闭上了双眼。21XX年,一位行将就木的老人跪坐于坟前,禁不住泪如泉

  2. 第二个方法挺不错。NewHead代表新的头节点,通过递归找到最后一个节点之后,就把这个节点赋给NewHead,然后一直返回返回,中途这个值是没有变化的,一边返回一边把相应的指针方向颠倒,最后结束时返回新的头节点到主函数。