forked from allicen/Java-1000
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseOfTerrorists.java
More file actions
63 lines (54 loc) · 1.94 KB
/
BaseOfTerrorists.java
File metadata and controls
63 lines (54 loc) · 1.94 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
60
61
62
63
package base_of_terrorists;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class BaseOfTerrorists {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new FileReader("input.txt"));
String[] baseInfo = sc.nextLine().split(" ");
int n = Integer.parseInt(baseInfo[0]);
int m = Integer.parseInt(baseInfo[1]);
char[][] base = new char[n][m];
int lineIndex = 0;
while (n > 0) {
String line = sc.nextLine();
base[lineIndex] = line.toCharArray();
lineIndex++;
n--;
}
String[] mapInfo = sc.nextLine().split(" ");
n = Integer.parseInt(mapInfo[0]);
m = Integer.parseInt(mapInfo[1]);
char[][] map = new char[n][m];
lineIndex = 0;
while (sc.hasNextLine()) {
map[lineIndex] = sc.nextLine().toCharArray();
lineIndex++;
}
int result = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (map[i][j] == base[0][0] || map[i][j] == '#') {
boolean exit = false;
for (int k = 0; k < base.length; k++) {
for (int l = 0; l < base[k].length; l++) {
if (i+k >= n || j+l >= m) {
exit = true;
break;
} else if (base[k][l] != map[i+k][j+l] && map[i+k][j+l] != '#') {
exit = true;
break;
}
}
if (exit) break;
}
if (!exit) result++;
}
}
}
PrintWriter out = new PrintWriter(System.out);
out.println(result);
out.flush();
}
}