예제 #1
0
        public InputFile(string filePath)
        {
            using (var file = File.OpenText(filePath))
            {
                var testCaseCount = int.Parse(file.ReadLine());

                testCases = new List<TestCase>(testCaseCount);

                for (var i = 0; i < testCaseCount; i++)
                {
                    var tokens = file.ReadLine().Split(' ').Select(int.Parse).ToArray();

                    var N = tokens[0];
                    var K = tokens[1];
                    var table = new Table(N);

                    for (var row = 0; row < N; row++)
                    {
                        var input = file.ReadLine().ToArray();
                        Debug.Assert(input.Length == N);

                        for (var col = 0; col < N; col++)
                            table[row,col] = input[col];
                    }

                    testCases.Add(new TestCase { Table = table, K = K });
                }
            }
        }
예제 #2
0
 static bool IsWinner(Table table, char player, int K)
 {
     for (var row = 0; row < table.Width; row++)
     {
         for (var col = 0; col < table.Width; col++)
         {
             if (IsWinnerAtPoint(table, player, K, col, row, 0, 1)) return true;
             if (IsWinnerAtPoint(table, player, K, col, row, 1, 0)) return true;
             if (IsWinnerAtPoint(table, player, K, col, row, 1, 1)) return true;
             if (IsWinnerAtPoint(table, player, K, col, row, -1, 1)) return true;
         }
     }
     return false;
 }
예제 #3
0
        static bool IsWinnerAtPoint(Table table, char player, int K, int col, int row, int colInc, int rowInc)
        {
            if (table[col, row] == player)
            {
                if (K == 1) return true;

                col += colInc;
                if (col < 0 || col >= table.Width) return false;

                row += rowInc;
                if (row < 0 || row >= table.Width) return false;

                return IsWinnerAtPoint(table, player, K - 1, col, row, colInc, rowInc);
            }
            else return false;
        }
예제 #4
0
파일: Table.cs 프로젝트: UIILabsDev/CodeJam
        public Table ApplyGravityOnTheRight()
        {
            var t = new Table(Width);

            for (int row = 0; row < Width; row++)
            {
                int dstCol = Width-1;
                for (var srcCol = Width-1; srcCol >= 0; srcCol--)
                {
                    if (array[row, srcCol] != '.')
                        t.array[row, dstCol--] = array[row, srcCol];
                }
                while (dstCol >= 0)
                    t.array[row, dstCol--] = '.';
            }

            return t;
        }