Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include <algorithm>
- #include <string>
- #include <vector>
- #include <map>
- #include <stack>
- #include <queue>
- using namespace std;
- const int N = 1e6;
- int n, m, k;
- string s;
- string *nextbrackets(string &s) {
- int close_cnt = 0, open_cnt = 0, i;
- for (i = s.size() - 1; i >= 0; --i) {
- if (s[i] == '(') {
- ++open_cnt;
- if (close_cnt > open_cnt) {
- break;
- }
- }
- else {
- ++close_cnt;
- }
- }
- s = s.substr(0, max(i, 0));
- if (s.empty()) {
- return nullptr;
- }
- s.push_back(')');
- for (i = 0; i < open_cnt; ++i) {
- s.push_back('(');
- }
- for (i = 1; i < close_cnt; ++i) {
- s.push_back(')');
- }
- return &s;
- }
- int main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #else
- freopen(FNAME".in", "r", stdin);
- freopen(FNAME".out", "w", stdout);
- #endif
- ios::sync_with_stdio(false);
- cin >> s;
- cout << (nextbrackets(s) ? s : "-") << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement