-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathProgram.cs
More file actions
59 lines (45 loc) · 2.03 KB
/
Program.cs
File metadata and controls
59 lines (45 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
namespace The_Grid_Search {
class Program {
public static string GridSearch(string[] grid, string[] pattern) {
int gridSize = grid.Length;
int patternSize = pattern.Length;
for (int i = 0; i <= gridSize - patternSize; i++) {
int gridRowStringSize = grid[0].Length;
int patternRowStringSize = pattern[0].Length;
for (int j = 0; j <= gridRowStringSize - patternRowStringSize; j++) {
bool found = true;
for (int k = 0; k < patternSize; k++) {
if (!grid[i + k].Substring(j, pattern[0].Length).Equals(pattern[k])) {
found = false;
break;
}
}
if (found)return "YES";
}
}
return "NO";
}
static void Main(string[] args) {
int numberOfTestCases = Convert.ToInt32(Console.ReadLine().Trim());
for (int i = 0; i < numberOfTestCases; i++) {
string[] gridParameters = Console.ReadLine().Trim().Split(' ');
int gridRows = Convert.ToInt32(gridParameters[0]);
int gridColumns = Convert.ToInt32(gridParameters[1]);
string[] grid = new string[gridRows];
for (int row = 0; row < gridRows; row++) {
grid[row] = Console.ReadLine();
}
string[] patternParameters = Console.ReadLine().Trim().Split(' ');
int patternRows = Convert.ToInt32(patternParameters[0]);
int patternColumns = Convert.ToInt32(patternParameters[1]);
string[] pattern = new string[patternRows];;
for (int row = 0; row < patternRows; row++) {
pattern[row] = Console.ReadLine();
}
string result = GridSearch(grid, pattern);
Console.WriteLine(result);
}
}
}
}