QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#369458 | #6750. Calculate | xjx | WA | 1ms | 3608kb | C++11 | 786b | 2024-03-28 10:38:47 | 2024-03-28 10:38:48 |
Judging History
answer
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int d[3];
void f(vector<int>& a, vector<int>& b,char c){
if (c == '+') for (int i = 0;i < 3;i++)a[i] += b[i];
else a[0] -= b[0], a[1] += b[2], a[2] += b[1];
}
int main(){//-(-a+b)
string s;
cin >> s;
s = '(' + s + ')';
vector<char> a;
vector<vector<int>> c;
for (int i = 0;i < s.size();i++){
if (s[i] == '(')a.push_back('(');
else if (s[i] == ')') {
while (a.size() && a.back() != '(')
f(c[c.size() - 2], c[c.size() - 1], a.back()), c.pop_back(), a.pop_back();
a.pop_back();
}
else if (s[i] == '+' || s[i] == '-')a.push_back(s[i]);
else if (s[i] == '?')c.push_back({ 0,1,0 });
else c.push_back({s[i]-'0',0,0});
}
cout << c[0][0] + c[0][1] * 9 << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
input:
?+?
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3452kb
input:
(?+9)-(?+1)
output:
17
result:
ok 1 number(s): "17"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3608kb
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:
-151
result:
wrong answer 1st numbers differ - expected: '-63', found: '-151'