Advertisement
cap7ainjack

WordCount

Oct 4th, 2015
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Hmwrk_6_3
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. Dictionary<string,int> dictionary = new Dictionary<string, int>();
  15. string inputWords = File.ReadAllText("../../words.txt");
  16. string[] words = inputWords.Split(new string[] {Environment.NewLine}, StringSplitOptions.None);
  17.  
  18. using (var reader = new StreamReader("../../text.txt"))
  19. {
  20.  
  21. string currentSentence = reader.ReadLine().Replace("-", " ").Replace(", "," ").Replace("."," ");
  22.  
  23. string[] text = currentSentence.Split(new string[] {" "}, StringSplitOptions.None);
  24.  
  25. foreach (var textWord in text)
  26. {
  27. if (textWord == words[1] && dictionary.ContainsKey(textWord))
  28. {
  29. dictionary[textWord]++;
  30. }
  31.  
  32. else if (textWord == words[1])
  33. {
  34. dictionary.Add(textWord, 1);
  35. }
  36. }
  37.  
  38.  
  39. foreach (var word in dictionary)
  40. {
  41. Console.WriteLine("{0} - {1}", word.Key, word.Value);
  42. }
  43.  
  44.  
  45. }
  46.  
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement