计算文章中单词的出现次数和分别在哪一段,把结果存到MapTree里
比如有一篇txt文本,内容如下:
April
April is the fourth month of the year with 30 days. The name April comes from that Latin word
April in poetry.
Poets use "April" to mean the end of winter. For example: "April showers bring May flowers."
Autonomous communities of Spain
Spain has fifty smaller parts called provinces. In 1978 these parts came together, making the autonomous communities.
Before then, some of these provinces were together but were broken. The groups that were has two cities on the north coast of Africa: Ceuta and Melilla. They are called "autonomous cities".
也就是一个标题,下面几段文字。这就是一个段落。一个空行,下面是新的标题+文字。
现在要读取这个txt,然后计算每个单词在,比如“good”在文中的:1)一共出现在多少段落中。2)出现该单词的段落的标题是什么,以及在此段落中出现了几次。 讲结果存入TreeMap中。 未来可以输入一个单词,比如“good”,就能得出{标题,次数}这样的结果。
java
单词
------解决方案--------------------论坛上的人不是廉价劳动力,这种题并没有什么难点,只要你懂点java我不信你做不出来。
就是一个简单的查找的问题。
------解决方案--------------------思路应该是
1、吧文章按空行分开 没一部分的第一行为标题 剩余的为内容
2、将内容按空格 存入list中 遍历list 如果为新单词 存入另一个list中 不是新单词 则将个数+1
------解决方案--------------------用map做,没什么难度