add solution for hw4:3435
Some checks failed
Fast Reverse Tests / test (push) Successful in 12s
Reverse Tests / test (push) Successful in 7s
Sum Tests / test (push) Successful in 7s
Word Stat Tests / test (push) Failing after 5s

This commit is contained in:
2026-01-31 15:43:42 +05:00
parent 8173cf4dab
commit 6c42ebab03

View File

@@ -27,12 +27,15 @@ public class WordStatLengthSuffix {
} else {
if (sb.length() > 0) {
String word = sb.toString().toLowerCase();
if (word.length() != 1) {
word = word.substring(word.length() / 2);
if (wordMap.containsKey(word)) {
wordMap.get(word).count++;
} else {
wordMap.put(word, new WordInfo(word, 1, wordIndex));
wordIndex++;
}
}
sb.setLength(0);
}
}
@@ -59,9 +62,7 @@ public class WordStatLengthSuffix {
PrintWriter writer = new PrintWriter(outputFileName, "UTF-8");
for (WordInfo info : sortedWords) {
if (info.word.length() != 1) {
writer.println(info.word.substring(info.word.length() / 2) + " " + info.count);
}
writer.println(info.word + " " + info.count);
}
writer.close();