Advertisement
LZsolar

CodeJam#2

Apr 3rd, 2020
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.     int k; scanf("%d",&k);
  6.     for(int t=1;t<=k;t++){
  7.         string a,ans;
  8.         cin>>a;
  9.         int m=a.size(),f=0,l=0;
  10.         for(int i=0;i<m;i++){
  11.             int u=a[i]-'0';
  12.            
  13.             if(u==0){
  14.                 for(int j=0;j<l;j++){
  15.                     ans=ans+')';
  16.                 }l=0;f=0;
  17.             }
  18.             if(u<l){
  19.                 for(int j=0;j<l-u;j++){
  20.                     ans=ans+')';f--;
  21.                 }l=u;
  22.             }
  23.            
  24.             if(u>f){
  25.                 for(int j=0;j<u-f;j++){
  26.                     ans=ans+'(';
  27.                 }f=u;
  28.             }
  29.            
  30.             l=max(u,l);
  31.             ans=ans+a[i];
  32.         }
  33.          for(int i=0;i<l;i++){
  34.                     ans=ans+')';
  35.                 }
  36.         printf("Case #%d: ",t);
  37.         cout<<ans<<endl;
  38.     }
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement