Notice
Recent Posts
Recent Comments
Link
거북이처럼 코딩해도 괜찮으려나
20220512_TIL 본문
728x90
Today I Learn |
1. NFA to DFA - normal한 NFA to DFA 중 reconstruct fa까지 진행 |
작성한 Class NFA 코드
class NFA
{
public Dictionary<string, Dictionary<string, string[]>> nfa_dic = new Dictionary<string, Dictionary<string, string[]>>();
public int s; // number of states
public int t; // number of transitions
public string first_state; // first state
public string[] final_state; // final states
public void Enter_nfa()
{
// Input states and transitions
Console.Write("Enter the number of states: ");
s = int.Parse(Console.ReadLine());
Console.Write("Enter the number of transitions: ");
t = int.Parse(Console.ReadLine());
// Enter name of state and transition
for (int i = 0; i < s; i++) // state
{
Console.Write("\n" + i + ". state name: ");
string state = Console.ReadLine();
Dictionary<string, string[]> t_dic = new Dictionary<string, string[]>(); // 임시 저장
for (int j = 0; j < t; j++) // transition
{
Console.Write("\n" + i + ". transition name: ");
string transition = Console.ReadLine();
Console.Write("next states from state " + state + " through " + transition + ": ");
string next_state = Console.ReadLine();
t_dic.Add(transition, next_state.Split(' '));
}
nfa_dic.Add(state, t_dic); // add nfa
}
// Enter First state
Console.Write("first states: ");
first_state = Console.ReadLine();
// Enter Final state
Console.Write("final states: ");
final_state = Console.ReadLine().Split(' ');
}
public void Prinf_nfa()
{
Console.WriteLine("\nNFA => ");
foreach (var pair1 in nfa_dic)
{
Console.Write("Key: {0}, Value: ", pair1.Key);
foreach (var pair2 in pair1.Value)
{
Console.Write("{0}-[{1}] ", pair2.Key, String.Join(", ", pair2.Value)); ;
}
Console.WriteLine();
}
}
}
'TIL' 카테고리의 다른 글
20220517_TIL (0) | 2022.05.17 |
---|---|
20220516_TIL (0) | 2022.05.17 |
20220509_TIL (0) | 2022.05.09 |
20220503_TIL (0) | 2022.05.03 |
20220502_TIL (전체적 수정 기준일) (0) | 2022.05.02 |