add solution for hw4:3435
This commit is contained in:
@@ -27,12 +27,15 @@ public class WordStatLengthSuffix {
|
|||||||
} else {
|
} else {
|
||||||
if (sb.length() > 0) {
|
if (sb.length() > 0) {
|
||||||
String word = sb.toString().toLowerCase();
|
String word = sb.toString().toLowerCase();
|
||||||
|
if (word.length() != 1) {
|
||||||
|
word = word.substring(word.length() / 2);
|
||||||
if (wordMap.containsKey(word)) {
|
if (wordMap.containsKey(word)) {
|
||||||
wordMap.get(word).count++;
|
wordMap.get(word).count++;
|
||||||
} else {
|
} else {
|
||||||
wordMap.put(word, new WordInfo(word, 1, wordIndex));
|
wordMap.put(word, new WordInfo(word, 1, wordIndex));
|
||||||
wordIndex++;
|
wordIndex++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
sb.setLength(0);
|
sb.setLength(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,9 +62,7 @@ public class WordStatLengthSuffix {
|
|||||||
PrintWriter writer = new PrintWriter(outputFileName, "UTF-8");
|
PrintWriter writer = new PrintWriter(outputFileName, "UTF-8");
|
||||||
|
|
||||||
for (WordInfo info : sortedWords) {
|
for (WordInfo info : sortedWords) {
|
||||||
if (info.word.length() != 1) {
|
writer.println(info.word + " " + info.count);
|
||||||
writer.println(info.word.substring(info.word.length() / 2) + " " + info.count);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user