Не проходит по всем пунктам
package com.javarask.task19.task1918;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Знакомство с тегами
*/
public class Solution {
public static void main(String[] args) throws IOException {
String tagName = "<" + args[0];
String closedTag = "</" + args[0] + ">";
String name;
try (BufferedReader r = new BufferedReader(new InputStreamReader(System.in))) {
name = r.readLine();
}
StringBuilder builder = new StringBuilder();
try (FileReader reader = new FileReader(name)) {
while (reader.ready()) {
builder.append((char) reader.read());
}
}
String text = builder.toString();
int first = text.indexOf(tagName);
int count = 1;
for (int i = first + 1; i < text.length(); i++) {
if (first >= 0) {
if (text.indexOf(tagName, i) == -1 || (text.indexOf(closedTag, i) < text.indexOf(tagName, i))) {
count --;
if (count == 0) {
System.out.println(text.substring(first, text.indexOf(closedTag) + closedTag.length()));
first = text.indexOf(tagName, first + 1);
count = 1;
if (first > 0) i = first;
}
else i = text.indexOf(closedTag);
}
else if (text.indexOf(tagName, i) > 0) {
count++;
i = text.indexOf(tagName);
}
}
}
}
}
/*
find (index);
public static void find (int index) {
for (int i = index + 1; i < text.length(); i++) {
if (text.indexOf(closedTag, i) > text.indexOf(tagName, i))
find(text.indexOf(tagName));
else {
System.out.println(text.substring(i, text.indexOf(closedTag + closedTag.length())));
i = text.indexOf(closedTag);
}
}
}
*/