QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#182916 | #6750. Calculate | Kewu | RE | 0ms | 0kb | C++11 | 1.3kb | 2023-09-18 19:02:50 | 2023-09-18 19:02:51 |
answer
#include <bits/stdc++.h>
using namespace std;
const int N=5e3+10;
char Map[N];
int main()
{
gets(Map+1);int n=strlen(Map+1);
int ans=0;
for(int i=1;i<=n;++i)
{
if(Map[i]!='?'&&(Map[i]<'0'||Map[i]>'9')) continue;
int flag=1;
stack<char> t;
for(int j=1;j<i;++j)
{
if(Map[j]!='?'&&(Map[j]<'0'||Map[j]>'9'))
{
if(Map[j]=='+') continue;
if(Map[j]=='-')
{
if(!t.empty()&&t.top()=='-') t.pop(),flag=-flag;
else t.push('-'),flag=-flag;
}
if(Map[j]=='(')
t.push('(');
if(Map[j]==')')
{
while(t.top()!='(')
{
if(t.top()=='-') flag=-flag;
t.pop();
}
t.pop();
if(!t.empty()&&t.top()=='-') t.pop(),flag=-flag;
}
}
}
if(Map[i]=='?')
{
if(flag==1)
ans+=9;
}
else ans+=flag*(Map[i]-'0');
}
cout<<ans<<endl;
system("pause");
return 0;
}
/*
-(?+7)-(?-3)
-4
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
?+?
output:
18