QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227135 | #7525. Brackets | Piashy# | WA | 0ms | 3868kb | C++20 | 2.0kb | 2023-10-26 23:13:15 | 2023-10-26 23:13:15 |
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;
}
}
}
if (curr != "")
if (sz(curr) == 1) {
curr = "(" + curr + ")";
}
res.push_back(curr);
while (res[sz(res) - 1] == "+" || 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: 3868kb
input:
x+++y
output:
(x++)+(y)
result:
ok Participant's answer is correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
q+u+++h+++++o+q++
output:
(q)+(u++)+(h++)+(++o)+(q++)
result:
ok Participant's answer is correct
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3628kb
input:
++a+++b+++c+++d+e+++f+++g+h+j+k+++++i
output:
((++a)++)+(b++)+(c++)+(d)+(e++)+(f++)+(g)+(h)+(j)+(k++)+(++i)
result:
wrong answer Expression contains more parentheses than variables