Tencent 2020 summer internship interview game client (compression algorithms)

Tencent 2020 summer internship interview game client (compression algorithms)

Problem Description

Small Q want to give his friend a mysterious string, but he found that the string is too long,
so small Q developed a compression algorithm for string repeated portion is compressed,
for a continuous string S m identical strings will be compressed into m | S ,
for example, will be compressed into a string ABCABCABC [3 | ABC],
now small Q students received a string of small Q sent from, you can help him de compress it?

Enter a description

Input of the first line contains a string s, representing the compressed string.
Length S <= 1000;
S contains only uppercase letters, [,], |;
string length after decompression is not more than 100,000;
compression is not more than 10 layers recursive layers;

Output Description

Output a string representative of the decompressed string.

Example 1
Input
HG [3 | B [2 | CA]] F
output
HGBCACABCACABCACAF
described
HG [3 | B [2 | CA]] F-> HG [3 | BCACA] F-> HGBCACABCACABCACAF

注意:需考虑到中括号并列的情况,而非单纯括号嵌套

Ideas (string replacement)

  1. Flexible use of the string [、|、]location
  2. Determining a first position closing parenthesis
  3. Determine the corresponding left parenthesis and separated number |
  4. Determining replacement string between the right partition and the number in brackets
  5. Determining the number of repetitions between the left bracket and the delimiter
  6. To replace the portion between the left and right parentheses string obtained to give the new S
  7. 2 is repeated until no brackets S, S is the output
Published 15 original articles · won praise 7 · views 4945

Guess you like

Origin blog.csdn.net/qq_32472703/article/details/104881177