QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#347253 | #6750. Calculate | wtz2333 | WA | 0ms | 3876kb | C++17 | 735b | 2024-03-09 12:39:28 | 2024-03-09 12:39:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
vector<int> st;
// int flag = 1;// 0 zuo + 1 zuo - 2 you + 3 you -
int cnt = 0;
int n = s.size();
int ans = 0;
for(int i = 0;i < n;i ++) {
if(s[i] == '(') {
st.push_back(i);
}else if(s[i] == ')') {
if(i != 0 && s[i - 1] == '-') {
cnt --;
}
st.pop_back();
}else if(s[i] == '?') {
if(cnt % 2 == 0) {
ans += 9;
}
}else if(s[i] == '+') {
}else if(s[i] == '-') {
cnt ++;
}else {
if(cnt % 2 == 0) {
ans += s[i] - '0';
}else ans -= s[i] - '0';
}
}
cout << ans << endl;
}
// 0 1 1
// 1 0 0
// 0 0 1
// 1 1 1
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
input:
?+?
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
(?+9)-(?+1)
output:
17
result:
ok 1 number(s): "17"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3640kb
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:
42
result:
wrong answer 1st numbers differ - expected: '-63', found: '42'