uva817 According to Bartjens
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=100945#problem/C
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> #define REP(i,a,b) for(int i=a;i<=b;i++) #define MS0(a) memset(a,0,sizeof(a)) #define PII pair<int,int> using namespace std; typedef long long ll; const int maxn=1000100; const int INF=(1<<29); char s[maxn];int ls; int f[maxn]; int n; set<string> ans; char Fs[6]={'=','+','-','*'}; bool judge() { if(s[0]=='0'&&f[1]==0) return 0; REP(i,1,n-2){ if(f[i]&&s[i]=='0'){ if(f[i+1]==0) return 0; } } int cnt=0; REP(i,1,n-1) cnt+=f[i]; return cnt>0; } void update() { if(!judge()) return;/// pre_0 stack<int> st,sf; int tmp=0; vector<int> v; REP(i,0,n-2){ tmp=tmp*10+s[i]-'0'; if(f[i+1]){ v.push_back(tmp); tmp=0; v.push_back(-f[i+1]); } } tmp=tmp*10+s[n-1]-'0'; v.push_back(tmp); for(int i=0;i<v.size();i++){ tmp=v[i]; if(tmp>=0){ while(!sf.empty()&&sf.top()==-3){ tmp*=st.top();st.pop();sf.pop(); } st.push(tmp); } else sf.push(v[i]); } stack<int> fst,fsf; while(!st.empty()) fst.push(st.top()),st.pop(); while(!sf.empty()) fsf.push(sf.top()),sf.pop(); tmp=fst.top();fst.pop(); while(!fsf.empty()){ if(fsf.top()==-1) tmp+=fst.top(); else tmp-=fst.top(); fsf.pop();fst.pop(); } if(tmp==2000){ string res=""; res+=s[0]; REP(i,1,n-1){ if(f[i]) res+=Fs[f[i]]; res+=s[i]; } //if(res=="2100-100") //cout<<res<<"="<<tmp<<" "<<jud()<<endl; ans.insert(res); } } void dfs(int cur) { //cout<<cur<<" "<<n<<endl; if(cur==n){ update(); return; } //cout<<cur<<" "<<n<<endl; REP(i,0,3){ f[cur]=i; dfs(cur+1); } } int main() { freopen("in.txt","r",stdin); //cout<<(int)'+'<<" "<<(int)'-'<<" "<<(int)'*'<<endl; int casen=1; while(~scanf("%s",s)&&s[0]!='='){ n=strlen(s); s[n-1]='