QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#411456#6750. Calculatehuangbrother#WA 4ms3612kbC++17638b2024-05-15 14:19:032024-05-15 14:19:04

Judging History

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

  • [2024-05-15 14:19:04]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3612kb
  • [2024-05-15 14:19:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    s="+"+s;
    int ans=0;
    for(int i=1;i<s.size();i++){
        if(s[i]!='('&&s[i]!=')'&&s[i]!='+'&&s[i]!='-'){
            int res=0;
            int c=1;
            for(int j=i-1;j>=1;j--){
                if(s[j]=='(')res++;
                if(s[j]==')')res--;
                if(res>0){
                    if(s[j-1]=='-')c=-c;
                }
            }
            if(s[i]=='?'){
                if(c>0)ans+=9;
            }else {
                ans+=(s[i]-'0')*c;
            }
        }
    }
    cout<<ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3572kb

input:

?+?

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

(?+9)-(?+1)

output:

17

result:

ok 1 number(s): "17"

Test #3:

score: -100
Wrong Answer
time: 4ms
memory: 3572kb

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:

-219

result:

wrong answer 1st numbers differ - expected: '-63', found: '-219'