Advertisement
csaki

Fordítóprogramok 4. gyak

Oct 6th, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8.  
  9. namespace vegesdetautomata
  10. {
  11.     class FileHandler
  12.     {
  13.         private string _szoveg { get; set; }
  14.         public void Open(string fileName)
  15.         {
  16.  
  17.             using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
  18.             {
  19.                 using (StreamReader s = new StreamReader(fs))
  20.                 {
  21.                     while (!s.EndOfStream)
  22.                     {
  23.                         _szoveg = s.ReadToEnd();
  24.                         Console.WriteLine(_szoveg);
  25.                     }
  26.                 }
  27.             }
  28.         }
  29.  
  30.         public string Read(string filename)
  31.         {
  32.             Open(filename);
  33.             return _szoveg;
  34.         }
  35.  
  36.         public string[] ReadAndSplit(string filename)
  37.         {
  38.             return Read(filename).Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
  39.         }
  40.  
  41.         public void Save(string fileName)
  42.         {
  43.             using (StreamWriter writer = new StreamWriter(fileName, true))
  44.             {
  45.                 writer.Write(_szoveg);
  46.                 writer.Flush();
  47.             }
  48.  
  49.         }
  50.     }
  51.     class Program
  52.     {
  53.         static void Main(string[] args)
  54.         {
  55.             List<string> validStrings = new List<string>();
  56.             foreach (var str in new FileHandler().ReadAndSplit("proba.txt"))
  57.             {
  58.                 string A = "q0";
  59.                 for (int i = 0; i < str.Length && A != "error"; i++)
  60.                 {
  61.                     A = Delta(A, str[i]);
  62.                 }
  63.                 if (A != "error" && A != "q0") validStrings.Add(str);
  64.             }
  65.  
  66.             Console.WriteLine("\n\n--------------\nValid strings:");
  67.             foreach (var str in validStrings)
  68.             {
  69.                 Console.WriteLine(str);
  70.             }
  71.             Console.ReadLine();
  72.  
  73.         }
  74.  
  75.         static string Delta(string allapot, char s)
  76.         {
  77.            
  78.             switch (allapot + GetAllapot(s))
  79.             {
  80.                 case "q0-": return "q1";
  81.                 case "q0+": return "q1";
  82.                 case "q0N": return "q2";
  83.                 case "q1N": return "q2";
  84.                 case "q2N": return "q2";
  85.             }
  86.             return "error";
  87.         }
  88.  
  89.         static string GetAllapot(char str)
  90.         {
  91.             if (Char.IsDigit(str)) return "N";
  92.             else if (str.ToString() == "-") return str.ToString();
  93.             return "nö1q345göeqa83754zz"; // because fuck you, that's why
  94.         }
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement