예제 #1
0
        internal CaseOutput Solve()
        {
            var output = new CaseOutput(input.Grid, input.R, input.C);

            var rowBackFill = 0;

            for (int rr = 0; rr < input.R; rr++)
            {
                if (input.LettersInRow[rr] == 0)
                {
                    rowBackFill++;
                    continue;
                }
                var localRowBackFill = rowBackFill;
                rowBackFill = 0;

                var previousLetterCol = -1;
                for (int xx = 0; xx < input.LettersInRow[rr]; xx++)
                {
                    var currentLetterCol = input.LetterLocationsInRow[rr][xx];
                    var currentLetter    = input.Grid[rr, currentLetterCol];

                    int endColForThis = (xx == input.LettersInRow[rr] - 1) ? input.C - 1 : currentLetterCol;

                    for (int jj = previousLetterCol + 1; jj < endColForThis + 1; jj++)
                    {
                        for (int backfill = 0; backfill < localRowBackFill + 1; backfill++)
                        {
                            output.Grid[rr - backfill, jj] = currentLetter;
                        }
                    }

                    previousLetterCol = currentLetterCol;
                }
            }


            if (rowBackFill > 0)
            {
                for (int ii = 0; ii < rowBackFill; ii++)
                {
                    for (int jj = 0; jj < input.C; jj++)
                    {
                        output.Grid[input.R - 1 - ii, jj] = output.Grid[input.R - 1 - rowBackFill, jj];
                    }
                }
            }

            return(output);
        }
예제 #2
0
        public static void Output()
        {
            var input = new CaseOutput(new char[, ] {
                { 'a', 'b' }, { 'a', 'c' }
            }, 2, 2);

            input.ToString().Should().Be(@"
ab
ac");

            input = new CaseOutput(new char[, ] {
                { 'a', 'b', 'b' }, { 'a', 'c', 'd' }
            }, 2, 3);
            input.ToString().Should().Be(@"
abb
acd");
        }