Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- namespace Treehouse.CodeChallenges
- {
- public class LexicalAnalysis
- {
- public Dictionary<string, int> WordCount = new Dictionary<string, int>();
- public void AddWord(string word)
- {
- if (WordCount.ContainsKey(word))
- {
- WordCount[word]++;
- }
- else
- {
- WordCount.Add(word, 1);
- }
- }
- // Set the return type of the method to match the dictionary that will be returned
- public Dictionary<string, int> WordsWithCountGreaterThan (int num){
- // Create a new dictionary to hold the word with a count greater than num
- Dictionary<string, int> greaterWord = new Dictionary<string, int>();
- // loop though each item in the WordCount dictionary
- foreach (KeyValuePair<string,int> word in WordCount)
- {
- // Check if the value (count) of the word is greater than num
- if (word.Value > num)
- {
- // Add the word and it's value to the new dictionary if the word's count is greater than num
- greaterWord.Add(word.Key, word.Value);
- }
- }
- // Return the new dictionary
- return greaterWord;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement