UVa : 11821 (High-Precision Number)


import java.math.BigDecimal;
import java.util.Scanner;

public class Main{

	/**
	 * @param args
	 */
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner (System.in);
		
		int testCase = input.nextInt();
		BigDecimal res;
		BigDecimal num1;
		
		while ( testCase-- != 0 ) {
			res = BigDecimal.ZERO;
			num1 = BigDecimal.ZERO;
			do {
				res = res.add(num1);
				num1 = input.nextBigDecimal();
			} while ( num1.compareTo(BigDecimal.ZERO) != 0 );
			
			char output [] = res.toString().toCharArray();
			int len = output.length - 1;
			
			while ( len >= 0 && output [len] == '0' ) len--;
			if ( len >= 0 && output [len] == '.' ) len--;
			
			for ( int i = 0; i <= len; i++ ) System.out.print (output [i]);
			System.out.println ();
		}
	}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s