mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 15:31:43 +08:00
存量题库数据更新
This commit is contained in:
@@ -1,34 +1,34 @@
|
||||
<p>Write a bash script to calculate the frequency of each word in a text file <code>words.txt</code>.</p>
|
||||
|
||||
|
||||
|
||||
<p>For simplicity sake, you may assume:</p>
|
||||
|
||||
|
||||
|
||||
<ul>
|
||||
|
||||
<li><code>words.txt</code> contains only lowercase characters and space <code>' '</code> characters.</li>
|
||||
|
||||
<li>Each word must consist of lowercase characters only.</li>
|
||||
|
||||
<li>Words are separated by one or more whitespace characters.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
<p><strong>Example:</strong></p>
|
||||
|
||||
|
||||
|
||||
<p>Assume that <code>words.txt</code> has the following content:</p>
|
||||
|
||||
|
||||
|
||||
<pre>
|
||||
|
||||
the day is sunny the the
|
||||
|
||||
the sunny is is
|
||||
|
||||
<p>Write a bash script to calculate the <span data-keyword="frequency-textfile">frequency</span> of each word in a text file <code>words.txt</code>.</p>
|
||||
|
||||
<p>For simplicity sake, you may assume:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>words.txt</code> contains only lowercase characters and space <code>' '</code> characters.</li>
|
||||
<li>Each word must consist of lowercase characters only.</li>
|
||||
<li>Words are separated by one or more whitespace characters.</li>
|
||||
</ul>
|
||||
|
||||
<p><strong class="example">Example:</strong></p>
|
||||
|
||||
<p>Assume that <code>words.txt</code> has the following content:</p>
|
||||
|
||||
<pre>
|
||||
the day is sunny the the
|
||||
the sunny is is
|
||||
</pre>
|
||||
|
||||
<p>Your script should output the following, sorted by descending frequency:</p>
|
||||
|
||||
<pre>
|
||||
the 4
|
||||
is 3
|
||||
sunny 2
|
||||
day 1
|
||||
</pre>
|
||||
|
||||
<p><b>Note:</b></p>
|
||||
|
||||
<ul>
|
||||
<li>Don't worry about handling ties, it is guaranteed that each word's frequency count is unique.</li>
|
||||
<li>Could you write it in one-line using <a href="http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-4.html">Unix pipes</a>?</li>
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user