QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#191218#7525. BracketsDays_of_Future_Past#WA 1ms5644kbC++141.1kb2023-09-29 20:37:332023-09-29 20:37:33

Judging History

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

  • [2023-09-29 20:37:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5644kb
  • [2023-09-29 20:37:33]
  • 提交

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 j = i;
    while (ip[j] == '+' && j <= n) ++j;
    int var_pos = j;
    ++j;
    while (j <= n && ip[j] == '+') ++j;
    int nxt_var = j;

    int cnt_pre_incr = (var_pos - i) / 2;
    int cnt_post_incr = (nxt_var - var_pos - 1) / 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 = j;
  }
  printf("%s\n", ans + 1);
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 5584kb

input:

x+++y

output:

(x++)+y

result:

ok Participant's answer is correct

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5644kb

input:

q+u+++h+++++o+q++

output:

q+(u++)+((h++)++)+o+(q++)

result:

wrong answer Division by operands in answer is wrong, position: 6