Код: Выделить всё
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import java.io.IOException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class dataann2
{
public static void main(String[] args) throws IOException
{
printGridFromGoogleDoc("https://docs.google.com/document/d/e/2PACX- 1vRPzbNQcx5UriHSbZ-9vmsTow_R6RRe7eyAU60xIF9Dlz-vaHiHNO2TKgDi7jy4ZpTpNqM7EvEcfr_p/pub");
}
public static void printGridFromGoogleDoc(String docUrl) throws IOException
{
Document doc = Jsoup.connect(docUrl).get();
List positions = new ArrayList(); // [row, col, charAsInt]
// Regex: col char row — allows multiple spaces
Pattern pattern = Pattern.compile("(\\d+)\\s+(.)\\s+(\\d+)");
// Each
is one visible line in Google Docs
for (Element p : doc.select("p"))
{
// Join all spans with spaces so coordinates stay intact
String combined = String.join(" ",
p.select("span").eachText().stream()
.filter(t -> !t.isBlank())
.map(t -> t.replace('\u00A0', ' ')) // normalize spaces
.toList()
).trim();
// Find *all* coordinates in the paragraph
Matcher matcher = pattern.matcher(combined);
while (matcher.find())
{
try
{
int x = Integer.parseInt(matcher.group(1));
char ch = matcher.group(2).charAt(0);
int y = Integer.parseInt(matcher.group(3));
positions.add(new int[]{y, x, ch});
}
catch (NumberFormatException ignored)
{
}
}
}
if (positions.isEmpty())
{
System.out.println("No coordinate lines found — check if the Google Doc is public and formatted correctly.");
return;
}
// Sort by row first, then column (row-major order)
positions.sort(Comparator.comparingInt(p -> p[0])
.thenComparingInt(p -> p[1]));
// Determine grid size
int maxRow = positions.stream().mapToInt(p -> p[0]).max().orElse(0);
int maxCol = positions.stream().mapToInt(p -> p[1]).max().orElse(0);
// Build and fill grid
char[][] grid = new char[maxRow + 1][maxCol + 1];
for (char[] row : grid) Arrays.fill(row, ' ');
for (int[] p : positions)
{
grid[p[0]][p[1]] = (char) p[2];
}
// Print grid
for (char[] row : grid)
{
System.out.println(new String(row));
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... google-doc