Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define toDigit(c) (c-'0')
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     ios::sync_with_stdio(0);
  10.     cin.tie(0);
  11.    
  12.     int t, lvlO = 0, lvlC = 0;
  13.     cin >> t;
  14.    
  15.     vector<string> ansV;
  16.     vector<string> strV;
  17.     for (int i = 0; i < t; i ++) {
  18.         int lvlO = 0, lvlC = 0;
  19.         string tmp, ans = "";
  20.         cin >> tmp;
  21.         strV.push_back(tmp);
  22.     }
  23.  
  24.     for (int i = 0; i < t; i ++) {
  25.         string tmp = strV[i], ans = "";
  26.         for (auto c : tmp) {
  27.             int ci = toDigit(c);
  28.             if (lvlO == ci){
  29.                 ans += to_string(ci);
  30.                 continue;
  31.             }
  32.             for (; lvlO < ci; lvlO++, lvlC--)
  33.                 ans += "(";
  34.             if (lvlO == ci) {
  35.                 ans += to_string(ci);
  36.                 continue;
  37.             }
  38.             for (; lvlO > ci; lvlC ++, lvlO --)
  39.                 ans += ")";
  40.             if (lvlO == ci) {
  41.                 ans += to_string(ci);
  42.                 continue;
  43.             }
  44.         }
  45.         for (; lvlC != 0; lvlC ++, lvlO --)
  46.             ans += ")";
  47.  
  48.         ansV.push_back(ans);
  49.     }
  50.     for (int i = 0; i < t; i ++){
  51.         cout << ansV[i];
  52.         if (i != t - 1)
  53.             cout << endl;
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement