QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#757781#6750. CalculateDGH_Didi#WA 0ms3656kbC++201.4kb2024-11-17 13:25:302024-11-17 13:25:31

Judging History

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

  • [2024-11-17 13:25:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3656kb
  • [2024-11-17 13:25:30]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
using i64 = long long;

string s;
int cnt, ans;
stack<bool> f;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (isdigit(s[i])) {
            if (cnt & 1) {
                ans -= s[i] - '0';
            } else {
                ans += s[i] - '0';
            }
            continue;
        }
        if (s[i] == '+') {
            f.push(true);
        } else if (s[i] == '-') {
            if (s[i + 1] == '(') {
                f.push(false);
                cnt++;
            } else {
                if (isdigit(s[i + 1])) {
                    if (cnt & 1) {
                        ans += s[i + 1] - '0';
                    } else {
                        ans -= s[i + 1] - '0';
                    }
                } else {
                    if (cnt & 1) {
                        ans += 9;
                    }
                }
                ++i;
            }
        } else if (s[i] == ')') {
            if (f.empty()) {
                continue;
            }
            bool x = f.top();
            f.pop();
            if (!x) {
                cnt--;
            }
        } else if (s[i] == '?') {
            if (cnt % 2 == 0) {
                ans += 9;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

詳細信息

Test #1:

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

input:

?+?

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

(?+9)-(?+1)

output:

17

result:

ok 1 number(s): "17"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3572kb

input:

((9)-(((8)-(2))+(((1+(1))-(1+((2)+2+2)))+(5)+4))+(((7)-((9)+3))-((8)-(0-(2))+0))+((6)-(6+(((4)-(9))-(8-((9)+(1))+(0)))+(2-((9)+7))-(1)))-((((7)+(1))-((3)+(3)))-((2)-((6)-((3)-(8)))))+(2+0-((6)-(1))))-((((3)-(((0)+((4)-(9))+((6+8)+4)+(5)-(4-(3)-(8)))-((8)-(2))))+(((2)-(4))+(6)-(2))+(6-(1))-((2+9)-(3+...

output:

389

result:

wrong answer 1st numbers differ - expected: '-63', found: '389'