Guest User

CH1 Super Hard Sum

a guest
Jun 20th, 2011
1,208
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.io.IOException;
  4. import java.math.BigInteger;
  5. import java.util.StringTokenizer;
  6.  
  7. /*
  8.  * Tuenti Contest
  9.  * Challenge 1 - Super Hard Sum
  10.  * Author: Pedro Antonio Pardal Jimena
  11.  * Email: pardal@alu.uma.es
  12.  */
  13.  
  14. public class HardSum
  15. {
  16.     private static String sumaLinea( String linea )
  17.     {
  18.         BigInteger sum = BigInteger.ZERO;      
  19.         StringTokenizer st = new StringTokenizer( linea, " +" );
  20.        
  21.         while ( st.hasMoreTokens() )
  22.         {
  23.             BigInteger next;
  24.            
  25.             try
  26.             {
  27.                 next = new BigInteger( st.nextToken() );
  28.             }
  29.             catch ( NumberFormatException e )
  30.             {
  31.                 next = BigInteger.ZERO;
  32.             }
  33.            
  34.             sum = sum.add( next );
  35.         }
  36.        
  37.         return sum.toString();
  38.     }
  39.    
  40.     public static void main( String[] args ) throws IOException
  41.     {
  42.         BufferedReader reader = new BufferedReader( new InputStreamReader( System.in ) );
  43.        
  44.         while ( reader.ready() )
  45.         {
  46.             String linea = reader.readLine();
  47.            
  48.             System.out.println( sumaLinea( linea ) );
  49.         }
  50.     }
  51. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×