Доброго времени суток. Не проходит последний пункт проверки, вроди всё достаточно просто, и вывод соответствует примеру, но валидатор упорно отказывается принимать.
package com.javarush.task.task19.task1918;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/*
Знакомство с тегами
*/
public class Solution {
public static void main(String[] args) {
StringBuilder textBuilder = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
BufferedReader fileReader = new BufferedReader(new FileReader(reader.readLine()))) {
while (fileReader.ready()) {
textBuilder.append(fileReader.readLine());
}
String text = textBuilder.toString();
unpacker(text, args[0]);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static void unpacker(String input, String tag) {
Pattern pattern = Pattern.compile(tag);
Matcher matcher = pattern.matcher(input);
int tagCounter = 0, begin = 0, end = 0;
boolean isInside = false;
boolean isMultiple = false;
while (matcher.find()) {
tagCounter = input.charAt(matcher.start() - 1) != '/' ? tagCounter + 1 : tagCounter - 1;
if (tagCounter == 1 && !isInside) {
begin = matcher.start() - 1;
isInside = true;
} else if (tagCounter == 0) {
end = matcher.end() + 1;
isInside = false;
System.out.println(input.substring(begin, end));
if (isMultiple) {
unpacker(input.substring(begin + tag.length() + 2, end - (tag.length() + 3)), tag);
}
} else if (tagCounter > 1) {
isMultiple = true;
}
}
}
}