import java.io.BufferedReader; import java.io.IOEx...
Tạo vào: 17 tháng 6, 2025
Tạo vào: 17 tháng 6, 2025
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
text// 8 direction unit-steps: ↖ ↑ ↗ ← → ↙ ↓ ↘ private static final int[] DX = {-1, -1, -1, 0, 0, 1, 1, 1}; private static final int[] DY = {-1, 0, 1, -1, 1,-1, 0, 1}; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine().trim()); char[][] grid = new char[n][n]; for (int i = 0; i < n; i++) { String line = br.readLine().trim(); // remove any spaces just in case (defensive) line = line.replaceAll("\\s+", ""); grid[i] = line.toCharArray(); } String word = br.readLine().trim(); int wordLen = word.length(); int total = 0; for (int r = 0; r < n; r++) { for (int c = 0; c < n; c++) { if (grid[r][c] != word.charAt(0)) continue; // try every direction for (int dir = 0; dir < 8; dir++) { int x = r, y = c; int k; for (k = 1; k < wordLen; k++) { x += DX[dir]; y += DY[dir]; if (x < 0 || y < 0 || x >= n || y >= n) break; if (grid[x][y] != word.charAt(k)) break; } if (k == wordLen) { // full match total++; } } } } System.out.println(total); }
} give it in the format of image
{"prompt":"Generate a high‑resolution screenshot‑style image (1024×768) of a dark‑themed Java IDE (e.g., IntelliJ IDEA Darcula) displaying a file named Main.java with syntax‑highlighted code. The code shown should exactly be:\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\n // 8 direction unit-steps: ↖ ↑ ↗ ← → ↙ ↓ ↘\n private static final int[] DX = {-1, -1, -1, 0, 0, 1, 1, 1};\n private static final int[] DY = {-1, 0, 1, -1, 1,-1, 0, 1};\n\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n int n = Integer.parseInt(br.readLine().trim());\n char[][] grid = new char[n][n];\n\n for (int i = 0; i < n; i++) {\n String line = br.readLine().trim();\n // remove any spaces just in case (defensive)\n line = line.replaceAll("\\s+", "");\n grid[i] = line.toCharArray();\n }\n\n String word = br.readLine().trim();\n int wordLen = word.length();\n\n int total = 0;\n for (int r = 0; r < n; r++) {\n for (int c = 0; c < n; c++) {\n if (grid[r][c] != word.charAt(0)) continue;\n\n // try every direction\n for (int dir = 0; dir < 8; dir++) {\n int x = r, y = c;\n int k;\n for (k = 1; k < wordLen; k++) {\n x += DX[dir];\n y += DY[dir];\n if (x < 0 || y < 0 || x >= n || y >= n) break;\n if (grid[x][y] != word.charAt(k)) break;\n }\n if (k == wordLen) { // full match\n total++;\n }\n }\n }\n }\n\n System.out.println(total);\n }\n}","size":"1024x768","n":1,"transparent_background":false}
Here’s your Java solution presented as a clean, dark-theme code-editor screenshot. Let me know if you’d like any tweaks or a different layout!