QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#371791 | #6750. Calculate | Delisha21U | WA | 1ms | 3584kb | C++17 | 1.6kb | 2024-03-30 16:24:25 | 2024-03-30 16:24:26 |
Judging History
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'