-
Notifications
You must be signed in to change notification settings - Fork 0
/
giai_ma_xau_ki_tu.cpp
55 lines (53 loc) · 1.57 KB
/
giai_ma_xau_ki_tu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool check(char s){
if(s >= 'a' && s <= 'z') return true;
return false;
}
int main(){
int t; cin >> t;
while(t--){
string s; cin >> s;
stack<string> st;
for(int i = s.size() - 1; i >= 0; i--){
if(s[i] == ']') st.push(to_string(s[i]));
else{
if(check(s[i])){
st.push(string(1,s[i]));
}
if(s[i] == '['){
string e = "";
while(st.top() != to_string(']') &&!st.empty()){
e += st.top();
st.pop();
}
st.pop();
st.push(e);
}
else if(s[i] >= '0' && s[i] <= '9'){
string k = "";
int mark = -1;
for(int j = i; j >= 0; j--){
if(check(s[j]) || s[j] == '[' || s[j] == ']' ){ mark = j; break;}
k = s[j] + k;
}
int g = stoll(k);
string h = st.top();
st.pop();
k = "";
while(g--){
k += h;
}
st.push(k);
}
}
}
string ans = "";
while(!st.empty()){
ans = ans + st.top();
st.pop();
}
cout<<ans<<endl;
}
}