[Problem description]
There is a demon who speaks in a very concise and abstract language of his own, and no one can understand it, but his language is a gradual interpretation of the language that adults can understand, because his language is abstracted by the following two forms of rules:
(1) α->β1β2 "βm
(2) (θδ1δ2 "Δn)->θδnθδn-1" θδ1θ
In both of these forms, the explanations are expressed from left to right. Try to write a system of interpretation of the Devil's language, explaining his words to adults who can understand them. [Basic requirements]
The following two specific rules and the above rule form (2) are implemented. An uppercase letter denotes the word of the Devil's language; the lowercase letters denote the words of the human language; the Greek alphabet denotes variables that can be substituted with uppercase or lowercase letters. Devil's language can contain human words.
(1) B-TAdA (2) A--SAE [test data]
B (EHNXGZ) b interpreted as Tsaedsaeezegexenehetsaedsae
If you set the correspondence between the lowercase letters and the Chinese characters as shown in the table below, the Devil says, "A goose in the sky chases a goose and geese goose down a goose on the ground a goose in the sky." T/D/s/a/e/z/g/x/n/h/-"day/ground/up/one/goose/chase/catch/down/egg/hate/
1#include <stdio.h>2 3 intMain () {4 Charstack[ +],temp,dec;5 inti =0, d =0, J;6 7printf"Please enter the Demon language:");8 9 while(temp = GetChar ())! ='#'){Ten if(Temp <='Z'&& Temp >='a'){ OneStack[i] =temp; Ai++; - } - if(temp = ='A'){ theStack[i] ='s'; stack[i+1] ='a'; stack[i+2] ='e'; -i = i +3; - } - if(temp = ='B'){ +Stack[i] ='T'; stack[i+1] ='s'; stack[i+2] ='a'; stack[i+3] ='e'; stack[i+4] ='D'; stack[i+5] ='s'; stack[i+6] ='a'; stack[i+7] ='e'; -i = i +8; + } A if(temp = ='('){ at while(temp = GetChar ())! =')'){ -Stack[i] =temp; -i++;d + +;//D is the counter -}//stack the words of the Lord in parentheses - CharTemp_1[d]; - for(j =0; J < d;j++){ inTEMP_1[J] = stack[i-1]; -i--; to}//the Devil language in parentheses out of the stack +Dec = stack[i-1];//Find Xita - //put the translated Devil's language on the stack the for(j =0; J < d;j++){ *Stack[i] =Dec; $stack[i+1] =Temp_1[j];Panax Notoginsengi = i +2; - } the //i = i + 2; +Stack[i] = Dec;//let I go to the place where it should be Ai++; the } + } - for(j =0; J < i;j++){ $ if(Stack[j] = ='T') printf ("days"); $ if(Stack[j] = ='D') printf ("to"); - if(Stack[j] = ='s') printf ("on"); - if(Stack[j] = ='a') printf ("a"); the if(Stack[j] = ='e') printf ("Goose"); - if(Stack[j] = ='Z') printf ("Chase");Wuyi if(Stack[j] = ='g') printf ("Catch"); the if(Stack[j] = ='x') printf ("under"); - if(Stack[j] = ='N') printf ("Egg"); Wu if(Stack[j] = ='h') printf ("Hate"); - } About $ return 0; -}
The key is the language of the Devil's parenthesis translation that is more cumbersome.
There is the online input of B (EHNXGZ) b in this program will appear: A goose on the ground a goose chase Goose Goose Goose Goose Geese hate goose goose in the sky a goose on the ground a goose
This is because in this line of the Lord's language, Theta is E, and there is also e in the parentheses in this paragraph of the Devil's language (in fact I should have deleted the extra theta, but lazy ^_-).
The Devil problem (C language Implementation)