using System; using System.IO; using System.Text.RegularExpressions; public class Problem1 { public static void Main() { FileStream file = new FileStream("DATA5.txt", FileMode.Open); StreamReader sr = new StreamReader(file); String temp = sr.ReadToEnd(); String[] lines = Regex.Split(temp, "\n"); String output = ""; FileStream file2 = new FileStream("OUT5.txt", FileMode.Create); StreamWriter sw = new StreamWriter(file2); int current = 0; for (int i = 0; i < 5; i++) { int WATERUNITS = Convert.ToInt32(lines[current]); int COLS = Convert.ToInt32(lines[current + 1]); int ROWS = Convert.ToInt32(lines[current + 2]); Char[,] map = new Char[ROWS, COLS]; for(int j = 0; j < ROWS; j++) { for(int k = 0; k < COLS; k++) { map[j,k] = lines[current + 3 + j][k]; } } sw.WriteLine(flood(map, COLS, ROWS, WATERUNITS)); current += (ROWS + 4); } sw.Close(); file2.Close(); } public static int flood(Char[,] map, int cols, int rows, int wunits) { int count = 0; for (int i = 0; i < wunits; i++) { Console.WriteLine("qqqq"); int cRow = 0; int cCol = 0; if (map[0,0] == '#') return 0; while ( !(cRow + 1 >= rows || map[cRow + 1, cCol] == '#' || map[cRow + 1, cCol] == '*' ) || !(cCol + 1 >= cols || map[cRow, cCol + 1] == '#' || map[cRow, cCol + 1] == '*' )) { if (map[cRow + 1,cCol] != '#' && map[cRow + 1,cCol] != '*' && cRow + 1 < rows) { cRow = cRow + 1; } else if (map[cRow,cCol + 1] != '#' && map[cRow,cCol + 1] != '*' && cCol + 1 < cols) { cCol = cCol + 1; } } if (map[cRow,cCol] == 'A') count++; map[cRow,cCol] = '*'; for (int j = 0; j < rows; j++) { for (int k = 0; k < cols; k++) { Console.Write(map[j, k]); } Console.WriteLine(); } Console.WriteLine("check!!"); } return count; } }