The government of a small but important country has decided that the alphabet needs to be streamlined and reordered. Uppercase letters will be eliminated. They will issue a royal decree in the form of a String of B and A characters. The first character in the decree specifies whether a must come ( B )Before b in the new alphabet or ( A )After b . The second character determines the relative placement of b and c , etc. So, for example, "BAA" means that a must come Before b , b must come After c , and c must come After d .
Any letters beyond these requirements are to be excluded, so if the decree specifies k comparisons then the new alphabet will contain the first k+1 lowercase letters of the current alphabet.
Create a class Alphabet that contains the method choices that takes the decree as input and returns the number of possible new alphabets that conform to the decree. If more than 1,000,000,000 are possible, return -1.
Definition
魔王語(yǔ)言解釋
[問(wèn)題描述]
有一個(gè)魔王總是使用自己的一種非常精練而又抽象的語(yǔ)言講話,沒(méi)有人能聽得懂,但他的語(yǔ)言是可以逐步解釋成人能聽懂的語(yǔ)言,因?yàn)樗恼Z(yǔ)言是由以下兩種形式的規(guī)則由人的語(yǔ)言逐步抽象上去的:
(1) α 轉(zhuǎn)換為 β1β2…βm
(2) (θδ1δ2…δn) 轉(zhuǎn)換為 θδnθδn-1… θδ1θ
在這兩種形式重,從左到右均表示解釋。試寫一個(gè)魔王語(yǔ)言的解釋兄,把他的話解釋成人能聽得懂的話。
[基本要求]
用下述兩條具體規(guī)則和上述規(guī)則形式(2)實(shí)現(xiàn)。設(shè)大寫字母表示魔王語(yǔ)言的詞匯;小寫字母表示人的語(yǔ)言詞匯;希臘字母表示可以用大寫字母或小寫字母代換的變量。魔王語(yǔ)言可含人的詞匯。
(1)B 轉(zhuǎn)換為 tAdA
(2)A 轉(zhuǎn)換為 sae
[測(cè)試數(shù)據(jù)]
B(exnxgz)B解釋成tsaedsaeezegexenehetsaedsae
若將小寫字母與漢字建立下表所示的對(duì)應(yīng)關(guān)系,則魔王說(shuō)的話是:“天上一只鵝地上一只鵝鵝追鵝趕鵝下鵝蛋鵝恨鵝天上一直鵝地上一只鵝”。
t d s a e z g x n h
天 地 上 一只 鵝 追 趕 下 蛋 恨