社区讨论

Segmentation Fault (Core dumped)

P8815[CSP-J 2022] 逻辑表达式参与者 3已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@m2j4pcv0
此快照首次捕获于
2024/10/21 22:45
去年
此快照最后确认于
2025/11/04 16:34
4 个月前
查看原帖
HTML
<html>
  <head>
    <title>Segmentation Fault</title>
  </head>
  <body>
    #include <bits/stdc++.h>

using namespace std;

bool compare(char a, char b) {
    if (a == '|') return true;
    return (b == '&');
}

int main() {
    string s;
    cin >> s;
    stack < char > sta1;
    stack < char > sta2;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '0' || s[i] == '1') {
            sta2.push(s[i]);
        } else if (s[i] == ')') {
            while (sta1.top() != '(') {
                sta2.push(sta1.top());
                sta1.pop();
            }
            sta1.pop();
        } else if (s[i] == '(') {
            sta1.push(s[i]);
        } else {
            while (compare(s[i], sta1.top())) {
                sta2.push(sta1.top());
                sta1.pop();
            }
            sta1.push(s[i]);
        }
    }
    while (!sta1.empty()) {
        sta2.push(sta1.top());
        sta1.pop();
    }
    char ans[int(2e6)];

    return 0;
}
  </body>
</html>

回复

3 条回复,欢迎继续交流。

正在加载回复...