import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.Stack; public class euler13 { public static void main(String[]args) { String[] s = new String[100]; int l = 0; File f = new File("13.txt"); try { Scanner in = new Scanner(f); while (in.hasNextLine()) { String line = in.nextLine(); s[l++] = line; } in.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } int digit; int carry = 0; Stack st = new Stack(); for (int j = 49; j >= 0; j--) { int sum = 0; for (int i = 0; i < 100; i++) { sum += Character.getNumericValue(s[i].charAt(j)); } sum += carry; digit = sum % 10; carry = sum / 10; st.push(new Integer(digit)); } st.push(carry); int count = 0; while (count++ < 10) { System.out.println(st.pop()); } } }
Leave a Reply