give code for this in java in the format shown in ...
Creado el: 12 de julio de 2025
Creado el: 12 de julio de 2025
pythonfrom PIL import Image import matplotlib.pyplot as plt img = Image.open('/mnt/data/87819068_SKC1272025_18834.png') plt.imshow(img) plt.axis('off') (-0.5, 1365.5, 767.5, -0.5)
pythonimg2 = Image.open('/mnt/data/87819068_SKC1272025_18857.png') plt.imshow(img2) plt.axis('off') (-0.5, 1365.5, 767.5, -0.5)
pythonimport numpy as np plt.figure(figsize=(6,4)) plt.imshow(img2.crop((100,300,400,500))) <matplotlib.image.AxesImage at 0x7ea1cec84e60>
pythonplt.imshow(img2.crop((100,450,400,650))) <matplotlib.image.AxesImage at 0x7ea16decd9a0>
pythonplt.figure(figsize=(6,4)) plt.imshow(img2.crop((100,600,650,800))) <matplotlib.image.AxesImage at 0x7ea16e10d220>
pythonplt.figure(figsize=(6,2)) plt.imshow(img2.crop((120,480,600,540))) plt.axis('off') (-0.5, 479.5, 59.5, -0.5)
pythonplt.figure(figsize=(6,2)) plt.imshow(img2.crop((100,510,600,580))) plt.axis('off') (-0.5, 499.5, 69.5, -0.5)
pythonplt.figure(figsize=(6,2)) plt.imshow(img2.crop((100,450,400,510))) plt.axis('off') (-0.5, 299.5, 59.5, -0.5)
pythonplt.figure(figsize=(6,2)) plt.imshow(img2.crop((100,475,400,530))) plt.axis('off') (-0.5, 299.5, 54.5, -0.5)
Here’s the completed solution in the exact skeleton shown in the screenshots:
javaimport java.util.*; public class TestClass { // str is the input string public static String shortestAnagram(String str) { int n = str.length(); // try every possible block length (must divide n and give ≥ 2 blocks) for (int len = 1; len <= n / 2; len++) { if (n % len != 0) continue; // block size must divide n // frequency count for the first block int[] base = new int[26]; for (int i = 0; i < len; i++) base[str.charAt(i) - 'a']++; boolean ok = true; // compare every subsequent block’s frequency with the first for (int start = len; start < n; start += len) { int[] cur = new int[26]; for (int i = start; i < start + len; i++) cur[str.charAt(i) - 'a']++; if (!Arrays.equals(base, cur)) { ok = false; break; } } if (ok) // found the minimal-length block return str.substring(0, len); } return "-1"; // not a multigram } public static void main(String[] arg) { Scanner sc = new Scanner(System.in); String str = sc.nextLine().trim(); System.out.println(shortestAnagram(str)); sc.close(); } }
How it works
n/2
, so at least two blocks will exist).base
) for the first block.Arrays.equals
).-1
.