Advertisement
Guest User

Task

a guest
Apr 4th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6. int main(){
  7.  
  8.     int t;
  9.     scanf("%d", &t);
  10.  
  11.     for(int count=0; count<t; count++){
  12.  
  13.         string s, aux, aux2;
  14.         int abierto=0, cerrado=0;
  15.         cin >> aux2;
  16.  
  17.         s.push_back('0');
  18.         s.append(aux2);
  19.  
  20.         for(int i=1; i<s.size();i++){
  21.             if(s[i]!='0'){
  22.                 aux.push_back(s[i]);
  23.             }else if(abierto<(s[i]-'0')){
  24.                 while(abierto<(s[i]-'0')){
  25.                     aux.push_back('(');
  26.                     abierto++;
  27.                 }
  28.                 aux.push_back(s[i]);
  29.             }else{
  30.                 aux.push_back(s[i]);
  31.                 while(cerrado<abierto){
  32.                     aux.push_back(')');
  33.                     cerrado++;
  34.                     abierto--;
  35.                 }
  36.             }
  37.         }
  38.  
  39.         printf("Case #%d: ", count+1);
  40.         cout << aux;
  41.         printf("\n");
  42.     }
  43.  
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement