QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227132 | #7525. Brackets | Piashy# | WA | 0ms | 3624kb | C++20 | 2.0kb | 2023-10-26 23:03:43 | 2023-10-26 23:03:45 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define sz(a) (int) a.size()
const int inf = (int)1e9;
const ll linf = (ll)2e18;
const ll mod = (ll)1e9 + 7ll;
void solve() {
string s;
cin >> s;
vector <string> res;
int cond = 0; string curr;
int i = 0;
while (i < sz(s)) {
if (cond == 0) {
cond = 1;
if (s[i] == '+') {
curr = "(++";
curr += s[i + 2];
curr += ')';
i += 2;
//cout << curr << endl;
}
else {
curr = "";
curr += s[i];
//curr += ')';
//cout << curr << endl;
}
i++;
}
else {
if (s[i] == '+') {
if (s[i + 1] == '+') {
curr = "(" + curr + "++)";
i += 2;
}
if (sz(curr) == 1) {
curr = "(" + curr + ")";
}
res.push_back(curr);
res.push_back("+");
i++;
curr = "";
cond = 0;
}
else {
cout << "oops" << endl;
return;
}
}
}
if (curr != "")
if (sz(curr) == 1) {
curr = "(" + curr + ")";
}
res.push_back(curr);
if (res[sz(res) - 1] == "+")
res.pop_back();
for (auto st : res) {
cout << st;
}
cout << endl;
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//freopen("test.in", "r", stdin);
//freopen("test.in", "w", stdout);
//cout << fixed << setprecision(7);
//clock_t start = clock();
int tet = 1;
//cin >> tet;
while (tet--) {
solve();
}
//clock_t end = clock();
//ld seconds = (ld)(end - start) / CLOCKS_PER_SEC;
//cout << seconds << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
x+++y
output:
(x++)+(y)
result:
ok Participant's answer is correct
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3560kb
input:
q+u+++h+++++o+q++
output:
(q)+(u++)+(h++)+(++o)+(q++)+
result:
wrong answer Answer expression is different from the input one