package xxx.xxx.xxx;
/*
* Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.
* D://workspace6//AlgorithmTest//LargeSumInput.txt
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
public class LargeSum {
List<BigInteger> inputList = new ArrayList<BigInteger>();
public LargeSum(File inputFile) throws IOException{
this.readData(inputFile);
}
private void readData(File inputFile) throws IOException{
BufferedReader reader = new BufferedReader(new InputStreamReader(
new FileInputStream(inputFile), "utf-8"));
String line = "";
while ((line = reader.readLine()) != null) {
inputList.add(new BigInteger(line));
}
System.out.println(inputList);
System.out.println(inputList.size());
}
private void compute(){
BigInteger sum = BigInteger.ZERO;
for(int i=0; i<inputList.size();i++){
sum=sum.add(inputList.get(i));
}
System.out.println(sum);
System.out.println(sum.toString().substring(0, 10));
}
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
LargeSum largeSum = new LargeSum(new File("D://workspace6//AlgorithmTest//LargeSumInput.txt"));
largeSum.compute();
}
}
/*
* Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.
* D://workspace6//AlgorithmTest//LargeSumInput.txt
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
public class LargeSum {
List<BigInteger> inputList = new ArrayList<BigInteger>();
public LargeSum(File inputFile) throws IOException{
this.readData(inputFile);
}
private void readData(File inputFile) throws IOException{
BufferedReader reader = new BufferedReader(new InputStreamReader(
new FileInputStream(inputFile), "utf-8"));
String line = "";
while ((line = reader.readLine()) != null) {
inputList.add(new BigInteger(line));
}
System.out.println(inputList);
System.out.println(inputList.size());
}
private void compute(){
BigInteger sum = BigInteger.ZERO;
for(int i=0; i<inputList.size();i++){
sum=sum.add(inputList.get(i));
}
System.out.println(sum);
System.out.println(sum.toString().substring(0, 10));
}
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
LargeSum largeSum = new LargeSum(new File("D://workspace6//AlgorithmTest//LargeSumInput.txt"));
largeSum.compute();
}
}