QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#191224#7525. BracketsDays_of_Future_Past#WA 1ms5856kbC++141.3kb2023-09-29 20:43:392023-09-29 20:43:39

Judging History

你现在查看的是最新测评结果

  • [2023-09-29 20:43:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5856kb
  • [2023-09-29 20:43:39]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 4e6+10;

char ip[N];
int n;
int n_plus_back[N];
char ans[N];

int main() {
  scanf("%s", ip+1);
  n = strlen(ip + 1);
  for (int i = n; i > 0; --i) {
    if (ip[i] == '+')
      n_plus_back[i] = 1 + n_plus_back[i + 1];
  }
  int it = 0;
  for (int i = 1; i <= n;) {
    int var_pos;
    int nxt_var;
    int cnt_pre_incr;
    int cnt_post_incr;
    if (n_plus_back[i] == 2) {
      cnt_pre_incr = 1;
      var_pos = i + 2;
    } else { // n_plus_back[i] == 0
      cnt_pre_incr = 0;
      var_pos = i;
    }
    if (n_plus_back[var_pos + 1] >= 2) {
      cnt_post_incr = 1;
      nxt_var = var_pos + 4;
    } else {
      cnt_post_incr = 0;
      nxt_var = var_pos + 2;
    }

    for (int k = 0; k < cnt_post_incr; ++k) {
      ans[++it] = '(';
    }
    for (int k = 0; k < cnt_pre_incr; ++k) {
      ans[++it] = '(';
      ans[++it] = '+';
      ans[++it] = '+';
    }
    ans[++it] = ip[var_pos];
    for (int k = 0; k < cnt_pre_incr; ++k) {
      ans[++it] = ')';
    }
    for (int k = 0; k < cnt_post_incr; ++k) {
      ans[++it] = '+';
      ans[++it] = '+';
      ans[++it] = ')';
    }
    if (nxt_var <= n) {
      ans[++it] = '+';
    }
    i = nxt_var;
  }
  printf("%s\n", ans + 1);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5796kb

input:

x+++y

output:

(x++)+y

result:

ok Participant's answer is correct

Test #2:

score: 0
Accepted
time: 1ms
memory: 5848kb

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: 1ms
memory: 5856kb

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 Division by operands in answer is wrong, position: 5