P1928 Alien Code

alien code

topic description

With the umbrella, the disaster of 2012 cannot be completely avoided. The Earth Defense Team decided to seek help from the alien race. After a long time of hard work, the team finally received a reply from the alien life. But what the aliens sent over was a string of passwords. Only by unlocking the password can we know the accurate reply given by the aliens. The first process of unlocking the password is to decompress the password. For several consecutive identical substrings X \texttt{X}X will compress to[DX] \texttt{[DX]}[DX] of the form (DDD is an integer and1 ≤ D ≤ 99 1\leq D\leq991D99 ), say the stringCBCBCBCB \texttt{CBCBCBCB}CBCBCBCB is compressed to[4CB] \texttt{[4CB]}[4CB] or[2[2CB]] \texttt{[2[2CB]]}[2[2CB]] , similar to the latter compression and then compression is called double compression. If it is[2[2[2CB]]] \texttt{[2[2[2CB]]]}[2[2[2CB]]] is triple. Now we give you the password sent by the aliens, please unzip it.

input format

Enter a line, a string, representing the password sent by the aliens.

output format

Output one line, a string, representing the decompressed result.

Example #1

Sample Input #1

AC[3FUN]

Sample output #1

ACFUNFUNFUN

hint

【data range】

For 50% 50\%50% of the data: the length of the decompressed string is1000 1000Within 1000 , there is only triple compression at most.

For 100 % 100\%100% data: the length of the decompressed string is20000 20000Within 20,000 , there are only ten compressions at most. Guaranteed to contain only numbers, uppercase letters,[and].

#include <bits/stdc++.h>
#define LL long long 
using namespace std;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e9 + 10;
const int N = 1e6;

string read(){
    
    
    char c;
    int n;
    string s = "",s1;
    while(cin >> c){
    
    
        if(c == '['){
    
    
            cin >> n;
            s1 = read();
            while(n--){
    
    
                s += s1;
            }
        }
        else{
    
    
            if(c == ']'){
    
    
                return s;
            }
            else{
    
    
                s += c;
            }
        }
    }
}


int main(){
    
    
    string ans = read();
    cout << ans << endl;
    system("pause");
    return 0;
}   

Guess you like

Origin blog.csdn.net/Recursions/article/details/128530448