如何实现在C#中下推自动机? [英] How do I implement pushdown automaton in C#?

查看:129
本文介绍了如何实现在C#中下推自动机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想code本作的PDA。我怎么会做,在C#?

  A ^ NBC ^ N(N> = 0)
 

解决方案

算法:

阅读一个字母在从输入一个时间,在循环中。

第1阶段:

如果读了这封信是是,然后递增计数器,并重复第1阶段。如果读了这封信是不是a,然后进入下一个部分。

第2阶段:

如果读了这封信是B,然后进入下一个阶段。如果读了这封信是不是B则算法失败。

第三阶段:

如果,如果读了这封信是C,则递减计数器,并重复第3阶段如果阅读这封信是不是C,然后进入下一个阶段。

第四阶段:

如果计数器是零,那么该算法成功,否则失败。

I want to code this for PDA. How would I do that in C#?

a^nbc^n (n>=0)

解决方案

Algorithm:

Read one letter at a time from the input, in a loop.

Stage 1:

If the letter read is "a" then increment a counter, and repeat Stage 1. If the letter read is not "a" then proceed to the next part.

Stage 2:

If the letter read is "b" then proceed to the next stage. If the letter read is not "b" then the algorithm fails.

Stage 3:

If if the letter read is "c" then decrement the counter, and repeat Stage 3. If the letter read is not "c" then proceed to the next stage.

Stage 4:

If the counter is zero, then the algorithm succeeds, otherwise it fails.

这篇关于如何实现在C#中下推自动机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆