add solution for hw4:3435
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user