//SOL public static void Solve(Input inp, InOut.Ergebnis erg) { string[] arr = inp.arr; int len = inp.len; int index = 0, ptStart = 0; List <string> output = new List <string>(); while (index < arr.Length) { int currLen = 0; while (index < arr.Length) { if (currLen + arr[index].Length + (index - ptStart) > len) { break; // accumulated wordlength + new Word lenght + a Space for each word } currLen += arr[index++].Length; } //calculate line Spacing int wordCount = Math.Max(index - ptStart - 1, 1); int freeSpaces = len - currLen; int spacePerWord = (index < arr.Length ? freeSpaces / wordCount : 1); int remainder = (index < arr.Length ? freeSpaces % wordCount : 0); //Will never exceed Number of Words-1 in Line string buildLine = ""; for (; ptStart < index - 1; ptStart++) { buildLine += arr[ptStart] + Helfer.GenerateString(spacePerWord + (remainder-- > 0? 1:0)); } output.Add(buildLine + arr[ptStart++]); } erg.Setze(output.ToArray(), Complexity.LINEAR, Complexity.LINEAR); }