QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#369458#6750. CalculatexjxWA 1ms3608kbC++11786b2024-03-28 10:38:472024-03-28 10:38:48

Judging History

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

  • [2024-03-28 10:38:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3608kb
  • [2024-03-28 10:38:47]
  • 提交

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'