Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2020
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef vector<int> vi;
  6. typedef long long ll;
  7. typedef pair<int, int> pii;
  8. #define pb push_back
  9. #define mp make_pair
  10. #define endl '\n'
  11. #define fastio cin.tie(NULL); ios_base::sync_with_stdio(0)
  12.  
  13. int main(){
  14.   fastio;
  15.   int t;
  16.  
  17.   cin>> t;
  18.  
  19.   for(int x = 1; x <= t+1; ++x){
  20.     string s;
  21.     stack<char> opened;
  22.     getline(cin, s);
  23.     if(x!=1 )cout<< "Case #" << x-1<<": ";
  24.     for(int i =0; i<s.size(); ++i){
  25.       if(opened.empty()){
  26.         if(s[i] - '0'){
  27.           for(int j = 0; j< s[i] - '0'; ++j){
  28.             cout<< '(';
  29.             opened.push(')');
  30.           }
  31.         }
  32.       }
  33.       else{
  34.         if(s[i] - '0'){
  35.           if(s[i] - '0' > s[i-1] - '0'){
  36.             for(int j = 0; j< (s[i] - '0') - (s[i-1] - '0'); ++j){
  37.               cout<< '(';
  38.               opened.push(')');
  39.             }
  40.           }
  41.           else if(s[i] - '0' < s[i-1] - '0'){
  42.             for(int j = 0; j< abs((s[i] - '0') - (s[i-1] - '0')); ++j){
  43.               char topo = opened.top();
  44.               opened.pop();
  45.               cout<< topo;
  46.             }
  47.           }
  48.           // cout<< s[i];
  49.         }
  50.         else{
  51.           for(int j = 0; !opened.empty(); ++j){
  52.             cout<< ')';
  53.             opened.pop();
  54.           }
  55.         }
  56.       }
  57.       cout<< s[i];
  58.       if(i == s.size() - 1){
  59.         for(int j = 0; !opened.empty(); ++j){
  60.           char topo = opened.top();
  61.           opened.pop();
  62.           cout<< ')';
  63.         }
  64.       }
  65.     }
  66.     cout<< endl;
  67.   }
  68.   return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement