QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#371717#6750. CalculateDelisha21UWA 1ms3580kbC++171.5kb2024-03-30 15:10:312024-03-30 15:10:38

Judging History

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

  • [2024-03-30 15:10:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3580kb
  • [2024-03-30 15:10:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 5e5 + 10;
const int mod = 1e9;

stack<int> q;

void solve()
{
	int sum = 0;
	int ans = 1;
	string s;
	cin >> s;
	for (int i = 0; i < (int)s.size(); i++)
	{
		if (s[i] == '(')
		{
			if (i == 0)
			{
				q.push(1);
			}
			else if (s[i - 1] == '-')
			{
				q.push(-1);
				ans = -ans;
			}
			else
			{
				q.push(1);
			}
		}
		if (s[i] == ')')
		{
			ans = ans * q.top();
			q.pop();
		}
		if (s[i] == '?')
		{
			if (i == 0)
			{
				if (ans == 1)
					sum += 9;
			}
			else if (s[i - 1] == '-')
			{
				if (ans == -1)
					sum += 9;
			}
			else
			{
				if (ans == 1)
					sum += 9;
			}
		}
		if (s[i] >= 48 && s[i] <= 57)
		{
			if (i == 0)
			{
				int k = 0;
				while (s[i] >= 48 && s[i] <= 57)
				{
					k = k * 10 + s[i] - 48;
					i++;
				}
				if (ans == -1)
					k = -k;
				sum += k;
			}
			else if (s[i - 1] == '-')
			{

				int k = 0;
				while (s[i] >= 48 && s[i] <= 57)
				{
					k = k * 10 + s[i] - 48;
					i++;
				}
				if (ans == 1)
					k = -k;
				sum += k;
			}
			else
			{
				int k = 0;
				while (s[i] >= 48 && s[i] <= 57)
				{
					k = k * 10 + s[i] - 48;
					i++;
				}
				if (ans == -1)
					k = -k;
				sum += k;
			}
		}
	}
	cout << sum;
	return;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	t = 1;
	// cin >> t;

	while (t--)
	{
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3580kb

input:

?+?

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3560kb

input:

(?+9)-(?+1)

output:

17

result:

ok 1 number(s): "17"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3532kb

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:

302

result:

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