QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#404790 | #6750. Calculate | Lance# | WA | 1ms | 3780kb | C++14 | 1.5kb | 2024-05-04 18:37:06 | 2024-05-04 18:37:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
using ll=long long;
using ull=unsigned long long;
#define pi pair<int, int>
#ifdef LOCAL
#include"D:/Administrator/Documents/vscode/algo/debug.h"
#else
#define debug(...) 42
#endif
//const int N = 2e5 //Lance老师注意改一下数据范围
const int INF = 2e9 + 1000;
const ll INFLL = 8e18 + 1000;
mt19937 mrand(random_device{}());
//模板区域~~~~~~~
//模板结束~~~~~~~
void solve(){
string s;
ll ans=0;
bool sign=false,flag=false;
stack<bool> st;
st.push(false);
cin>>s;
for(int i=0;i<(int)s.size();i++){
if(s[i]>='0'&&s[i]<='9'){
//cout<<(sign^st.top())<<endl;
ans+=(sign^st.top()?-(s[i]-'0'):s[i]-'0');
}else if(s[i]=='?'){
//cout<<(sign^st.top())<<endl;
ans+=(sign^st.top()?0:9);
}else if(s[i]=='+'){
sign=false;
}else if(s[i]=='-'){
sign=true;
}else if(s[i]=='('){
st.push(sign);
sign=false;
}else if(s[i]==')'){
st.pop();
}
//cout<<(sign^st.top());
}
//cout<<endl;
cout<<ans;
}
signed main(){
#ifndef LOCAL
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
#ifdef LOCAL
freopen("D:/Administrator/Documents/vscode/in.txt","r",stdin);
freopen("D:/Administrator/Documents/vscode/out.txt","w",stdout);
#endif
int T = 1;
//cin >> T;
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3504kb
input:
?+?
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
(?+9)-(?+1)
output:
17
result:
ok 1 number(s): "17"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3780kb
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:
1147
result:
wrong answer 1st numbers differ - expected: '-63', found: '1147'