using System; using System.Collections.Generic; using System.Text; using System.IO; namespace Euler13 { class Program { //Find the first ten digits of the sum of one-hundred 50-digit numbers. static void Main(string[] args) { StreamReader strIn = File.OpenText(@"input.txt"); string stCurrentLine = null; Stack st = new Stack(); while ((stCurrentLine = strIn.ReadLine()) != null) st.Push(stCurrentLine); string[] stNumbers = st.ToArray(); //Start with the lowest digit StringBuilder stAns = new StringBuilder(""); ulong sum = 0; ulong remaining = 0; for (int i = stNumbers[0].Length - 1; i >= 0; --i) { for (int j = 0; j < stNumbers.Length; ++j) { sum += ulong.Parse(stNumbers[j][i].ToString()); } remaining = (sum % 10); stAns.Append(remaining.ToString()); sum -= remaining; sum /= 10; } for (int i = sum.ToString().Length - 1; i >= 0; --i) { stAns.Append(sum.ToString()[i]); } Console.Write("Ans: "); StreamWriter strOut = new StreamWriter(@"ans.txt", false, Encoding.Default); for (int i = stAns.ToString().Length - 1; i >= 0; --i) { Console.Write(stAns.ToString()[i]); strOut.Write(stAns.ToString()[i]); } Console.Write("\n"); strOut.Write("\n"); strOut.Close(); Console.ReadLine(); } } }