[Huawei OD machine test] Simplify strings [2023 B volume | 200 points]

 [ Huawei OD machine test]-Real questions!! Click here! !

Huawei OD machine test】Categorization of real test points!! Click here  !!

topic description

Given an input string, the string can only be composed of English letters (a~z, A~Z) and left and right parentheses (,). When there are parentheses in the character, the parentheses are in pairs. There can be one or more pairs of parentheses. The pair of parentheses will not be nested. The pair of parentheses can contain one or more English letters or no English letters.

When a pair of parentheses contains multiple English letters, these letters are mutually equivalent, and the equivalence relationship can be transferred between different pairs of parentheses, that is, when a and b are equivalent and b and c are equivalent, a and c are also equivalent,

In addition, uppercase and lowercase letters of the same English alphabet are equivalent to each other (even if they are distributed in different pairs of brackets)

To simplify this input string, output a new string,

The output string only needs to keep the characters in the input string that are not enclosed by the parentheses (according to the character order in the input string), and replace each character with the smallest equivalent character contained in the parentheses. If the simplified string is empty, please output "0"

Example: The input string is "never(dont)live(run)up(f)()", the initial set of equivalent characters is (d,o,n,t), r,u,n),

Guess you like

Origin blog.csdn.net/goldarmour/article/details/131712963