CHAPTER 11. STRINGS
84
Figure 11.4: a) Undesired
uniques set; b) desired
uniques set
1) algorithm RepeatedWordCount(
value)
2)
Pre:
value 6=
∅
3)
Post: the number of repeated words in
value is returned
4)
words ← value.Split(’ ’)
5)
uniques ← Set
6)
foreach
word in
words
7)
uniques.Add(
word.Strip())
8)
end foreach
9)
return
words.Length
−uniques.Count
10) end RepeatedWordCount
You will notice in the
RepeatedWordCount algorithm that we use the
Strip
method we referred to earlier in
Dostları ilə paylaş: