Не могу реализовать алгоритм с FileStream - C#
Формулировка задачи:
Здравствуйте. Не могу реализовать алгоритм с помощью чтения из файла (FileStream). Помогите пожалуйста.
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace К
{
class Program
{
static void Main(string[] args)
{
string[] Slova= { "привет","пока","ок","вет" };//Слова которые нужно найти в строке
string Stroka = "приветпока";//Строка
List<int> Sostoyaniya = FindAllSostoyaniya(Stroka, Slova);
int count = 3;
foreach (var item in Sostoyaniya)
{
Console.WriteLine(" Слово " + Slova[count] + " начинается с " + item + " позиции. ");
count--;
}
Console.ReadLine();
}
private const int Stroka = 20;
private const int Alphavit = 32;
private static int[] Out = new int[Stroka];
private static int[] FF = new int[Stroka];
private static int[,] GF = new int[Stroka, Alphavit];
private static int Algoritm(string[] Words, char NizkiyChar = 'а', char NaibolshiyChar = 'я')
{
Out = Enumerable.Repeat(0, Out.Length).ToArray();
FF = Enumerable.Repeat(-1, FF.Length).ToArray();
for (int i = 0; i < Stroka; ++i)
{
for (int j = 0; j < Alphavit; ++j)
{
}
}
int Sostoyaniya = 1;
for (int i = 0; i < Words.Length; ++i)
{
string KeyWord = Words[i];
int StartSostoyanie = 0;
for (int j = 0; j < KeyWord.Length; ++j)
{
int c = KeyWord[j] - NizkiyChar;
if (GF[StartSostoyanie, c] == -1)
{
GF[StartSostoyanie, c] = Sostoyaniya++;
}
StartSostoyanie = GF[StartSostoyanie, c];
}
Out[StartSostoyanie] |= (1 << i);
}
for (int c = 0; c < Alphavit; c++)
{
if (GF[0, c] == -1)
{
GF[0, c] = 0;
}
}
List<int> q = new List<int>();
for (int c = 0; c <= NaibolshiyChar - NizkiyChar; ++c)
{
if (GF[0, c] != -1 && GF[0, c] != 0)
{
FF[GF[0, c]] = 0;
q.Add(GF[0, c]);
}
}
while (Convert.ToBoolean(q.Count))
{
int Sostoyanie = q[0];
q.RemoveAt(0);
for (int c = 0; c <= NaibolshiyChar - NizkiyChar; ++c)
{
if (GF[Sostoyanie, c] != -1)
{
int Otkaz = FF[Sostoyanie];
while (GF[Otkaz, c] == -1)
{
Otkaz = FF[Otkaz];
}
Otkaz = GF[Otkaz, c];
FF[GF[Sostoyanie, c]] = Otkaz;
Out[GF[Sostoyanie, c]] |= Out[Otkaz];
q.Add(GF[Sostoyanie, c]);
}
}
}
return Sostoyaniya;
}
private static int FindNextSostoyaniya(int StartSostoyanie, char NextVvod, char NizkiyChar = 'а')
{
int Otvet = StartSostoyanie;
int c = NextVvod - NizkiyChar;
while (GF[Otvet, c] == -1)
{
Otvet = FF[Otvet];
}
return GF[Otvet, c];
}
public static List<int> FindAllSostoyaniya(string Text, string[] KeyWord, char NizkiyChar = 'а', char NaibolshiyChar = 'я')
{
Algoritm(KeyWord, NizkiyChar, NaibolshiyChar);
int StartSostoyanie = 0;
List<int> Value = new List<int>();
for (int i = 0; i < Text.Length; ++i)
{
StartSostoyanie = FindNextSostoyaniya(StartSostoyanie, Text[i], NizkiyChar);
if (Out[StartSostoyanie] == 0)
continue;
for (int j = 0; j < KeyWord.Length;j++)
{
if (Convert.ToBoolean(Out[StartSostoyanie] & (1 << j)))
{
Value.Insert(0, i - KeyWord[j].Length + 1);
}
}
}
return Value;
}
}
}Решение задачи: «Не могу реализовать алгоритм с FileStream»
textual
Листинг программы
NaibolshiyChar - NizkiyChar