Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef vector<int> vi;
- typedef long long ll;
- typedef pair<int, int> pii;
- #define pb push_back
- #define mp make_pair
- #define endl '\n'
- #define fastio cin.tie(NULL); ios_base::sync_with_stdio(0)
- int main(){
- fastio;
- int t;
- cin>> t;
- for(int x = 1; x <= t+1; ++x){
- string s;
- stack<char> opened;
- getline(cin, s);
- if(x!=1 )cout<< "Case #" << x-1<<": ";
- for(int i =0; i<s.size(); ++i){
- if(opened.empty()){
- if(s[i] - '0'){
- for(int j = 0; j< s[i] - '0'; ++j){
- cout<< '(';
- opened.push(')');
- }
- }
- }
- else{
- if(s[i] - '0'){
- if(s[i] - '0' > s[i-1] - '0'){
- for(int j = 0; j< (s[i] - '0') - (s[i-1] - '0'); ++j){
- cout<< '(';
- opened.push(')');
- }
- }
- else if(s[i] - '0' < s[i-1] - '0'){
- for(int j = 0; j< abs((s[i] - '0') - (s[i-1] - '0')); ++j){
- char topo = opened.top();
- opened.pop();
- cout<< topo;
- }
- }
- // cout<< s[i];
- }
- else{
- for(int j = 0; !opened.empty(); ++j){
- cout<< ')';
- opened.pop();
- }
- }
- }
- cout<< s[i];
- if(i == s.size() - 1){
- for(int j = 0; !opened.empty(); ++j){
- char topo = opened.top();
- opened.pop();
- cout<< ')';
- }
- }
- }
- cout<< endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement