1.
package
contestVolumes.volume118;
import java.math.BigInteger;
import java.util.Scanner;
/**
* FWP, Ausgewählte
Probleme aus dem ACM Programming Contest, SS10
* Problem: 11821 -
High-Precision Number
* Link:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=226&problem=2921&mosmsg=Submission+received+with+ID+8228002
*
* @author Siegfried
Ippisch
* @version 1.0
*
* Method : String,
BigInteger
* Status : Accepted
* Runtime: 0.132
*/
public class
HighPrecisionNumber {
public
static class HighPrecision{
private final BigInteger value;
public HighPrecision(BigInteger i){
this.value = i;
}
public HighPrecision(String s){
if(!s.contains("."))
s += ".0";
int i =
s.length()-s.indexOf(".")-1;
s = s.replace(".", "");
while(i++ < 30)
s += "0";
this.value = new BigInteger(s);
}
public HighPrecision add(HighPrecision other){
return new
HighPrecision(this.value.add(other.value));
}
public String toString(){
String s =
"000000000000000000000000000000"+this.value;
if(s.contains("-"))
s =
"-"+s.replace("-", "");
String before =
s.substring(0,s.length()-30);
before = new
BigInteger(before).toString();
String after =
s.substring(s.length()-30,s.length());
int i = 29;
while(i>=0 &&
after.charAt(i) == '0')
i--;
after = after.substring(0, i+1);
if(after.length() == 0)
return before;
return before + "." + after;
}
}
public
static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
while(n-- > 0){
String next = in.next();
HighPrecision sum = new
HighPrecision("0");
while(!next.equals("0")){
HighPrecision
d = new HighPrecision(next);
sum =
sum.add(d);
next =
in.next();
}
System.out.println(sum);
}
in.close();
}
}