题前废话:
咱也不知道咱写了个什么神奇的代码导致_rqy都看不明白它是怎么re掉的,
代码的大致思路是这样的:对于这样一个中缀表达式,先转化成它的后缀表达式的形式,然后利用P1449 后缀表达式 这道题的solution来求解这个式子,但是咱也不知道为啥咱也找不出来为啥,它的所有语句都是可以正常执行的,最后答案也求出来显示出来了,然后它就停止运行了呢???甚至于return 0(main函数中的)都可以执行呢qwq
贴一下代码吧,希望大佬们帮忙看一看啊qwq:
#include<bits/stdc++.h> using namespace std; int cnt,x,b,c,num; string a,d; stack<char> s1; stack<long long> s; int main(){ cin>>a; int len=a.size(); for(int i=0;i<len;i++){ if(a[i]>='0'&&a[i]<='9'){ d[cnt++]=a[i]; } else { if(a[i]=='+'||a[i]=='-'||a[i]=='*'){ char f=s1.top(); d[cnt++]='.'; if((a[i]=='+'||a[i]=='-')&&(f=='*')){ d[cnt++]=f; s1.pop(); } s1.push(a[i]); } } } d[cnt++]='.'; while(!s1.empty()){ d[cnt++]=s1.top(); s1.pop(); } for(int i=0;i<cnt;i++){ if(d[i]=='+'){x=s.top();s.pop();b=s.top();s.pop();c=x+b;s.push(c);} if(d[i]=='-'){x=s.top();s.pop();b=s.top();s.pop();c=b-x;s.push(c);} if(d[i]=='*'){x=s.top();s.pop();b=s.top();s.pop();c=x*b;s.push(c);} if(d[i]>='0'&&d[i]<='9'){ num*=10; num+=(d[i]-'0'); } if(d[i]=='.'&&num!=0) { s.push(num); num=0; } } cout<<s.top()%10000; }