📄 pkj.cs
字号:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Parser
{
class Pkj
{
static void Main(string[] args)
{
Console.Title="< N-State Simulator >";
Console.WriteLine("\t\tn-State Machine Simulator");
//code starts here
int t_symbols, t_states, e_states,c_state;
c_state = 1;
Console.Write("\nEnter Total Number of States for the matrix: ");
t_states=Convert.ToInt32(Console.ReadLine());
Console.Write("\nEnter Total Number of Symbols: ");
t_symbols =Convert.ToInt32(Console.ReadLine());
Console.Write("\n{0}x{1} Matrix",t_states,t_symbols);
e_states = t_states;
String[,] transition_table = new String[(t_states + 1),(t_symbols + 1)];
String [] symbol_arr = new String[t_symbols];
for (int i = 0; i < transition_table.GetLength(0); i++)
{
for (int j = 0; j < transition_table.GetLength(1); j++)
{
transition_table[i,j]="x";
}
}
transition_table[0,0]="#";
for (int ind = 1; ind <= t_symbols; ind++)
{
Console.Write("\nEnter Symbol {0}: ",ind);
symbol_arr[ind-1]=Console.ReadLine();
transition_table[0,ind]=symbol_arr[ind-1];
}//endfor
for (int ind = 1; ind <= t_states; ind++)
{
transition_table[ind, 0] = ind.ToString();
}
for (int row = 1; row < (transition_table.GetLength(0)-1); row++)
{
for (int col = 1; col < transition_table.GetLength(1); col++)
{
Console.Write("\nEnter Rule for State {0} & Symbol {1}: ",transition_table[row,0],transition_table[0,col]);
transition_table[row, col] = Console.ReadLine();
}
}
Console.Clear();
Console.WriteLine("\n\t<| Shape of Machine Formed |>\n");
for (int i = 0; i < transition_table.GetLength(0); i++)
{
for (int j = 0; j < transition_table.GetLength(1); j++)
{
Console.Write("\t"+transition_table[i,j]);
}
Console.WriteLine("\n");
}
String input_string = "";
Console.Write("\n\tEnter String to be tested: ");
input_string = Console.ReadLine();
char[] input_ch = new char[input_string.Length];
input_ch = input_string.ToCharArray();
String [] input_arr = new String[input_ch.Length];
for (int i = 0; i < input_ch.Length; i++)
{
input_arr[i] = input_ch[i].ToString();
}
foreach (String str in input_arr)
{
int symbol_ind = chSearch(str, symbol_arr);
symbol_ind++;
c_state = chTraverse(symbol_ind, transition_table, c_state);
if (c_state == e_states)
{
break;
}
}
if (c_state == e_states)
Console.WriteLine("\n\t Successfully terminated! YESSSSSSSSSSSS");
else
Console.WriteLine("\n\tString Not Valid dodo!");
Console.WriteLine("\n\n\n\t Press Any Key To Exit this stupid program created by wajiha and ahmad ");
Console.ReadKey();
}
public static int chSearch(String str, String[] arr)
{
int ind=0;
for (int n=0; n < arr.GetLength(0); n++,ind++)
{
if (str.CompareTo(arr[n]) == 0)
{
break;
}
}
return (ind);
}
public static int chTraverse(int ind, String[,] transition_table,int curr_state)
{
int value = Convert.ToInt32(transition_table[curr_state,ind]);
return value;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -