fork(2) download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  5.  
  6. int Rand(int l, int h){
  7. return uniform_int_distribution<int>(l, h)(rng);
  8. }
  9. int main(){
  10. int n = Rand(1, 100); // length of the regular bracket is 2 * n
  11. stack<char> st;
  12. int pref = 0;
  13. for (int i = 1; i <= n; ++i){
  14. int x = Rand(0, 1);
  15. if (x == 1){
  16. pref ++;
  17. st.push('(');
  18. cout << '(';
  19. }
  20. else{
  21. if (pref > 0) {
  22. pref--; st.push(')');
  23. cout << ')';
  24. }
  25. else{
  26. pref++; st.push('(');
  27. cout << '(';
  28. }
  29. }
  30. }
  31. while(st.size()){
  32. char c = st.top(); st.pop();
  33. cout << (c == '(' ? ')' : '(');
  34. }
  35. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty