Advertisement
ccbeginner

code jam Nesting Depth

Apr 4th, 2020
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. //code jam Nesting Depth
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main(){
  6.     int t;
  7.     cin >> t;
  8.     string s;
  9.     for(int c = 1; c <= t; ++c){
  10.         cin >> s;
  11.         cout <<"Case #" << c <<": ";
  12.         int cnt = 0;
  13.         for(int i = 0; i < s.size(); ++i){
  14.             int x = s[i] - '0';
  15.             for(; cnt < x; ++cnt)cout << '(';
  16.             for(; cnt > x; --cnt)cout << ')';
  17.             cout << x;
  18.         }
  19.         for(; cnt > 0; --cnt)cout << ')';
  20.         cout << '\n';
  21.     }
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement