QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#371791#6750. CalculateDelisha21UWA 1ms3584kbC++171.6kb2024-03-30 16:24:252024-03-30 16:24:26

Judging History

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

  • [2024-03-30 16:24:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3584kb
  • [2024-03-30 16:24:25]
  • 提交

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();
			cout << q.top() << endl;
			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++;
				}
				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++;
				}
				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++;
				}
				i--;
				if (ans == -1)
					k = -k;
				sum += k;
			}
		}
		cout << sum << " " << ans << endl;
	}

	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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3584kb

input:

?+?

output:

9 1
9 1
18 1

result:

wrong answer 1st numbers differ - expected: '18', found: '9'