QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#413482 | #6750. Calculate | Ymk | RE | 0ms | 3604kb | C++23 | 10.3kb | 2024-05-17 16:54:52 | 2024-05-17 16:54:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pair pair<ll,ll>
#define endl '\n'
#define N (int)2e5+7
#define INF 0x3f3f3f3f//????? INT_MAX ????С INT_MIN
void solve()
{
string s;
cin>>s;
stack<char>st;
stack<int>t;
int sum=0,n=0,mx=-1e9;
int a[10]={0,9,0,9};
for(int i=0;i<s.size();i++)
{
if(s[i]=='?') n++;
}
// cout<<n<<endl;
if(n==0)
{
for(int i=0;i<s.size();i++)
{
// cout<<s[i]<<endl;
if(s[i]=='('||s[i]=='+'||s[i]=='-')
{
st.push(s[i]);
}
else if((s[i]>='0'&&s[i]<='9'))
{
t.push(s[i]-'0');
// cout<<a[j]<<endl;
}
else if(s[i]==')')
{
stack<char>q;
stack<int>qu;
int cnt=0;
while(!st.empty()&&st.top()!='(')
{
if(cnt==0) cnt++;
char op=st.top();
st.pop();
q.push(op);
cnt++;
}
while(cnt--)
{
int x=t.top();
t.pop();
qu.push(x);
}
while(!q.empty()&&!qu.empty())
{
char op=q.top();
q.pop();
int x=qu.top();
qu.pop();
int y=qu.top();
qu.pop();
if(op=='+')
{
int k=x+y;
qu.push(k);
}
else if(op=='-')
{
int k=x-y;
qu.push(k);
}
}
st.pop();
t.push(qu.top());
}
}
stack<char>q;
stack<char>qu;
int cnt=0;
while(!st.empty())
{
if(cnt==0) cnt++;
char op=st.top();
st.pop();
q.push(op);
cnt++;
}
while(cnt--)
{
int x=t.top();
t.pop();
qu.push(x);
}
while(!q.empty())
{
char op=q.top();
q.pop();
int x=qu.top();
qu.pop();
int y=qu.top();
qu.pop();
if(op=='+')
{
int k=x+y;
qu.push(k);
}
else if(op=='-')
{
int k=x-y;
qu.push(k);
}
}
if(!qu.empty())
{
t.push(qu.top());
qu.pop();
}
int h=t.top();
// mx=max(h,mx);
t.pop();
cout<<h<<endl;
}
else if(n==1)
{
for(int j=0;j<2;j++)
{
for(int i=0;i<s.size();i++)
{
// cout<<s[i]<<endl;
if(s[i]=='('||s[i]=='+'||s[i]=='-')
{
st.push(s[i]);
}
else if((s[i]>='0'&&s[i]<='9')||s[i]=='?')
{
if(s[i]=='?') t.push(a[j]);
else t.push(s[i]-'0');
// cout<<a[j]<<endl;
}
else if(s[i]==')')
{
stack<char>q;
stack<int>qu;
int cnt=0;
while(!st.empty()&&st.top()!='(')
{
if(cnt==0) cnt++;
char op=st.top();
st.pop();
q.push(op);
cnt++;
}
while(cnt--)
{
int x=t.top();
t.pop();
qu.push(x);
}
while(!q.empty()&&!qu.empty())
{
char op=q.top();
q.pop();
int x=qu.top();
qu.pop();
int y=qu.top();
qu.pop();
if(op=='+')
{
int k=x+y;
qu.push(k);
}
else if(op=='-')
{
int k=x-y;
qu.push(k);
}
}
st.pop();
t.push(qu.top());
}
}
stack<char>q;
stack<char>qu;
int cnt=0;
while(!st.empty())
{
if(cnt==0) cnt++;
char op=st.top();
st.pop();
q.push(op);
cnt++;
}
while(cnt--)
{
int x=t.top();
t.pop();
qu.push(x);
}
while(!q.empty())
{
char op=q.top();
q.pop();
int x=qu.top();
qu.pop();
int y=qu.top();
qu.pop();
if(op=='+')
{
int k=x+y;
qu.push(k);
}
else if(op=='-')
{
int k=x-y;
qu.push(k);
}
}
if(!qu.empty())
{
t.push(qu.top());
qu.pop();
}
int h=t.top();
mx=max(h,mx);
t.pop();
}
cout<<mx<<endl;
}
else if(n==2)
{
for(int j=0;j<2;j++)
{
for(int l=2;l<4;l++)
{
bool bo=0;
for(int i=0;i<s.size();i++)
{
if(s[i]=='('||s[i]=='+'||s[i]=='-')
{
st.push(s[i]);
}
if((s[i]>='0'&&s[i]<='9')||s[i]=='?')
{
if(s[i]=='?')
{
if(!bo)
{
t.push(a[j]);
bo=1;
}
else t.push(a[l]);
}
else t.push(s[i]-'0');
}
if(s[i]==')')
{
stack<char>q;
stack<int>qu;
int cnt=0;
while(!st.empty()&&st.top()!='(')
{
if(cnt==0) cnt++;
char op=st.top();
st.pop();
q.push(op);
cnt++;
}
while(cnt--)
{
int x=t.top();
t.pop();
qu.push(x);
}
while(!q.empty()&&!qu.empty())
{
char op=q.top();
q.pop();
int x=qu.top();
qu.pop();
int y=qu.top();
qu.pop();
if(op=='+')
{
int k=x+y;
qu.push(k);
}
else if(op=='-')
{
int k=x-y;
qu.push(k);
}
}
st.pop();
t.push(qu.top());
}
}
stack<char>q;
stack<char>qu;
int cnt=0;
while(!st.empty())
{
if(cnt==0) cnt++;
char op=st.top();
st.pop();
q.push(op);
cnt++;
}
while(cnt--)
{
int x=t.top();
t.pop();
qu.push(x);
}
while(!q.empty())
{
char op=q.top();
q.pop();
int x=qu.top();
qu.pop();
int y=qu.top();
qu.pop();
if(op=='+')
{
int k=x+y;
qu.push(k);
}
else if(op=='-')
{
int k=x-y;
qu.push(k);
}
}
if(!qu.empty())
{
t.push(qu.top());
qu.pop();
}
mx=max(t.top(),mx);
t.pop();
}
}
cout<<mx<<endl;
}
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t=1;
// cin>>t;
while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
input:
?+?
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
(?+9)-(?+1)
output:
17
result:
ok 1 number(s): "17"
Test #3:
score: -100
Runtime Error
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+...