Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- freopen("brackets.in", "r", stdin);
- freopen("brackets.out", "w", stdout);
- string s;
- cin >> s;
- int l = s.size();
- int open = 0;
- for (int i = 0; i < l; i++)
- if (s[i] == '(')
- open++;
- int bal = 0;
- for (int i = 0; i < l; i++) {
- if (s[i] == '(')
- bal++;
- if (s[i] == ')')
- bal--;
- if (s[i] == '?') {
- if (open < l / 2) {
- open++;
- bal++;
- s[i] = '(';
- }
- else {
- bal--;
- s[i] = ')';
- }
- }
- if (bal < 0) {
- cout << "No\n";
- return 0;
- }
- }
- if (open != l / 2 || bal) {
- cout << "No\n";
- return 0;
- }
- cout << s << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement