-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
61 lines (49 loc) · 1.47 KB
/
Program.cs
File metadata and controls
61 lines (49 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GrammarTester
{
class Program
{
private static List<string> rules;
static void Main(string[] args)
{
rules = new List<string>() { "SA", "Sa", "ABb", "Ab", "BcC", "Bc", "CS", "Cd" };
var input = "cdbbd";
var word = "S";
if (test(input, word))
{
Console.WriteLine("Entrada correta.");
Console.ReadKey();
}
else
{
Console.WriteLine("Entrada incorreta.");
Console.ReadKey();
}
}
private static bool test(string input, string word)
{
var stateRecurse = new char();
if (word.Equals(input))
return true;
if (word.Length > input.Length)
return false;
stateRecurse = word.FirstOrDefault(x => char.ToUpper(x) == x);
if (stateRecurse == '\0')
return false;
foreach (var x in rules)
{
if (x.ElementAt(0).Equals(stateRecurse))
{
var wordAux = word.Replace(stateRecurse.ToString(), x.Remove(0, 1)).ToString();
if (test(input, wordAux))
return true;
}
}
return false;
}
}
}