using System; using System.Collections.Generic; using System.Text; using System.IO; namespace Markov { class Program { static bool Empty(string s) { return s == ""; } static void Main(string[] args) { string text = File.ReadAllText("cioran.txt").Replace('\n', ' ').Replace('\r', ' '); string[] cuvinte = text.Split(' '); List l = new List(cuvinte), l2 = new List(); l.RemoveAll(Empty); List lcuvinte = new List(l); l.Sort(); l2.Add(l[0]); for (int i = 1; i < l.Count; i++) if (l[i] != l[i - 1]) l2.Add(l[i]); Dictionary hashCuv = new Dictionary(); for (int i = 0; i < l2.Count; i++) hashCuv.Add(l2[i], i); Dictionary, List> hashMarkov = new Dictionary, List>(); for (int i = 2; i < lcuvinte.Count; i++) { KeyValuePair kvp = new KeyValuePair(hashCuv[lcuvinte[i - 2]], hashCuv[lcuvinte[i - 1]]); if (hashMarkov.ContainsKey(kvp) == false) hashMarkov[kvp] = new List(); hashMarkov[kvp].Add(hashCuv[lcuvinte[i]]); } foreach (KeyValuePair, List> kvp in hashMarkov) Console.WriteLine(kvp.Value.Count); } } }