using System; using System.IO; using System.Collections; using System.Text.RegularExpressions; public class Problem4 { public static void Main() { FileStream file = new FileStream("DATA4.txt", FileMode.Open); StreamReader sr = new StreamReader(file); String temp = sr.ReadToEnd(); String[] lines = Regex.Split(temp, "\n"); FileStream file2 = new FileStream("OUT4.txt", FileMode.Create); StreamWriter sw = new StreamWriter(file2); int count = 0; for(int i = 0; i < 2; i++) { int num = 0; if (lines[count].Length == 0) break; int amt = Convert.ToInt32(lines[count]); Console.WriteLine(amt); count++; int coins = Convert.ToInt32(lines[count]); Console.WriteLine(coins); ArrayList vals = new ArrayList(); for (int j = 1; j <= coins; j++) { count++; vals.Add( Convert.ToInt32(lines[count])); } vals.Sort(); int temp2 = amt; int start = vals.Count - 1; while (amt != 0) { num = 0; amt = temp2; for (int t = start - 1; t >= 0; t--) { num+=amt/Convert.ToInt32(vals[start]); amt = amt % Convert.ToInt32(vals[start]); if (amt == 0) break; int temp3 = amt; int numtemp = num; int start2 = start-1; for (int u = start2; u>= 0; u--) { num = numtemp; amt = temp3; for (int y = u; y >= 0; y--) { Console.Write("start2: "); Console.WriteLine(y); Console.Write("amt: "); Console.WriteLine(amt); num += amt / Convert.ToInt32(vals[y]); amt = amt % Convert.ToInt32(vals[y]); if (amt == 0) break; } if (amt == 0) break; } } start--; } Console.WriteLine(num); sw.WriteLine(num); count++; } sw.Close(); file2.Close(); } }