Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1.  string randomWords;
  2.             randomWords = "apple banana apple orange pineapple blueberry raspberry lemon watermelon banana pineapple " +
  3.                 "strawberry blueberry orange mango kiwi melon raspberry apple orange";
  4.  
  5.             Dictionary<string, int> wordsCount = new Dictionary<string, int>();
  6.  
  7.             string[] words = randomWords.Split(' ');
  8.  
  9.             foreach(string word in words)
  10.             {
  11.                 int count = 1;
  12.                 if (wordsCount.ContainsKey(word))
  13.                 {
  14.                     count = wordsCount[word] + 1;
  15.                     wordsCount[word] = count;
  16.                 }
  17.                
  18.             }
  19.             foreach(var pair in wordsCount)
  20.             {
  21.                 Console.WriteLine($"{pair.Key} - > {pair.Value}");
  22.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement