RT。
知道是输出的地方错了但不会改,路过dalao教教。
我的想法是在后面加上-0,但实际上没有用...因为翻转后也是按优先级的,并不是有一个不存在的"括号"。
比如3*9+2-0,翻转后变为0-3*9+2并不是想要的0-(3*9+2)。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
int p,q;
//p=a+b+12+0-6666-0
//q=a-b+21+0-6666-0
//p=a+b-6654
//q=a-b-6645
//p-q=2b-9
//a=(p+q+13299)/2
//b=p-q/2
bool tag=false;
inline void solve(int x,string &s){
string tmp="";
while(x){
tmp+=char(x%9+'0');
x/=9;
}
reverse(tmp.begin(),tmp.end());
int n=tmp.size();
for(int i=0;i<n;i++){
s+=tmp[i];
for(int j=1;j<=n-i-1;j++)
s+='*',s+='9';
if(i!=n-1)s+='+';
}
return;
}
signed main(){
cin>>p>>q;
if(p<q)tag=true,swap(p,q);
if((p+q)%2!=0){
int a=(p+q+13299)/2;
int b=(p-q+9)/2;
string s="",t="";
solve(a,s);
solve(b,t);
string res=s+"+"+t+"-0+12+0-6666-0";
if(!tag)cout<<res<<"\n";
else{
reverse(res.begin(),res.end());
cout<<res<<"\n";
}
return 0;
}
int a=(p+q+13332)/2;
int b=(p-q)/2;
string s="",t="";
solve(a,s);
solve(b,t);
string res=s+"+"+t+"-0+0-6666-0\n";
if(!tag)cout<<res<<"\n";
else{
reverse(res.begin(),res.end());
cout<<res<<"\n";
}
return 0;
}