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.
精彩评论