Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace vegesdetautomata
- {
- class FileHandler
- {
- private string _szoveg { get; set; }
- public void Open(string fileName)
- {
- using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
- {
- using (StreamReader s = new StreamReader(fs))
- {
- while (!s.EndOfStream)
- {
- _szoveg = s.ReadToEnd();
- Console.WriteLine(_szoveg);
- }
- }
- }
- }
- public string Read(string filename)
- {
- Open(filename);
- return _szoveg;
- }
- public string[] ReadAndSplit(string filename)
- {
- return Read(filename).Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
- }
- public void Save(string fileName)
- {
- using (StreamWriter writer = new StreamWriter(fileName, true))
- {
- writer.Write(_szoveg);
- writer.Flush();
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- List<string> validStrings = new List<string>();
- foreach (var str in new FileHandler().ReadAndSplit("proba.txt"))
- {
- string A = "q0";
- for (int i = 0; i < str.Length && A != "error"; i++)
- {
- A = Delta(A, str[i]);
- }
- if (A != "error" && A != "q0") validStrings.Add(str);
- }
- Console.WriteLine("\n\n--------------\nValid strings:");
- foreach (var str in validStrings)
- {
- Console.WriteLine(str);
- }
- Console.ReadLine();
- }
- static string Delta(string allapot, char s)
- {
- switch (allapot + GetAllapot(s))
- {
- case "q0-": return "q1";
- case "q0+": return "q1";
- case "q0N": return "q2";
- case "q1N": return "q2";
- case "q2N": return "q2";
- }
- return "error";
- }
- static string GetAllapot(char str)
- {
- if (Char.IsDigit(str)) return "N";
- else if (str.ToString() == "-") return str.ToString();
- return "nö1q345göeqa83754zz"; // because fuck you, that's why
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement