Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Hmwrk_6_3
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string,int> dictionary = new Dictionary<string, int>();
- string inputWords = File.ReadAllText("../../words.txt");
- string[] words = inputWords.Split(new string[] {Environment.NewLine}, StringSplitOptions.None);
- using (var reader = new StreamReader("../../text.txt"))
- {
- string currentSentence = reader.ReadLine().Replace("-", " ").Replace(", "," ").Replace("."," ");
- string[] text = currentSentence.Split(new string[] {" "}, StringSplitOptions.None);
- foreach (var textWord in text)
- {
- if (textWord == words[1] && dictionary.ContainsKey(textWord))
- {
- dictionary[textWord]++;
- }
- else if (textWord == words[1])
- {
- dictionary.Add(textWord, 1);
- }
- }
- foreach (var word in dictionary)
- {
- Console.WriteLine("{0} - {1}", word.Key, word.Value);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement