Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define sf(nn) scanf ("%d", &nn)
- #define sfll(nn) scanf ("%lld", &nn)
- #define pf printf
- #define casepf(nn) printf ("Case #%d: ",nn)
- #define out(nn) cout <<nn <<endl
- #define loop(var,start,till) for(int var=start; var<till; var++)
- #define pb push_back
- #define mem(a,b) memset(a,b,sizeof(a))
- #define mp make_pair
- #define ll long long int
- #define inf 2e9
- #define llinf 2e18
- #define READ(f) freopen(f,"r",stdin)
- #define WRITE(f) freopen(f,"w",stdout)
- #define Unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
- #define mx 20000005
- #define mod 1000000007
- int dx[8]={0,0,1,-1,1,1,-1,-1};
- int dy[8]={1,-1,0,0,1,-1,1,-1};
- string str;
- int lim,fl,inwhich;
- ll calcsum(int n)
- {
- ll totsum=0,sum;
- for(int i=0; i<str.length(); )
- {
- sum = 0;
- for(int j=0; j<n && i<str.length(); j++)
- {
- sum = (ll) ((sum*10) + (ll)(str[i]-'0'));//cout<<(ll)(str[i]-'0')<<endl;
- i++;
- }//cout<<sum<<endl;
- //sum = sum + temp;
- totsum += sum;
- }
- return totsum;
- }
- string tostring(ll res)
- {
- string curstr = "";
- while(res != 0)
- {
- ll temp = (res%10);
- curstr += ((char) temp+'0');
- res /= 10;
- }
- reverse(curstr.begin(),curstr.end());
- return curstr;
- }
- int ar[200005],vis[200005];
- void printans(int n)
- {//out(n);//cin.ignore();
- for(int i=0; i<str.length(); )
- {
- for(int j=0; j<n && i<str.length(); j++)
- {
- cout<<str[i];
- i++;
- }//out(i);
- if(i < str.length()) pf("+");
- }
- pf("\n");
- }
- void backtrack(int n,int len,string cur)
- {//cout<<n<<" "<<lim<<endl;
- if(n == lim+1)
- {
- int pre = 0,tot=0;
- for(int i=1; i<=lim; i++)
- {//out(ar[i]);
- int temp = 0;
- for(int j=pre; j<ar[i]; j++)
- {
- temp = (temp*10) + ((int)(cur[j]-'0'));//out(temp);//cout<<cur[j]<<"////\n";
- }
- pre = ar[i];
- tot += temp;
- }
- //cout<<tot<<" ... "<<endl;
- int temp = 0;
- for(int j=pre; j<cur.length(); j++)
- {
- temp = (temp*10) + ((int)(cur[j]-'0'));//out(temp);
- }
- tot += temp;
- //cout<<"tot : "<<tot<<endl;
- string res = tostring(tot);
- int jogfol = 0;
- for(int i=0; i<res.size(); i++)
- {
- jogfol += ((int)res[i]-'0');
- }
- string strjogfol = tostring(jogfol);//cout<<strjogfol<<" "<<strjogfol.size()<<endl;
- if(strjogfol.size() == 1 && !fl)
- {
- fl = 1;
- ///printans
- printans(inwhich);
- int pre = 0,tot=0;
- for(int i=1; i<=lim; i++)
- {
- int temp = 0,flnow=0;
- for(int j=pre; j<ar[i]; j++)
- {
- cout<<cur[j];
- flnow=1;
- }
- pre = ar[i];
- if(flnow)cout<<"+";
- }
- int temp = 0;
- for(int j=pre; j<cur.length(); j++)
- {
- cout<<cur[j];
- }
- cout<<endl;
- for(int i=0; i<res.size(); i++)
- {
- if(!i)cout<<res[i];
- else cout<<"+"<<res[i];
- }
- cout<<endl;
- return;
- }
- }
- for(int i=1; i<len; i++)
- {
- if(!vis[i])
- {
- vis[i] = 1;
- ar[n] = i;
- backtrack(n+1,len,cur);
- vis[i] = 0;
- }
- }
- }
- int main()
- {
- int n;
- sf(n);
- fl=0;
- cin>> str;
- if(str.size() == 1)
- {
- cout<<str<<endl;
- cout<<str<<endl;
- cout<<str<<endl;
- return 0;
- }
- else if(str.size() == 2 && str[1] == '0')
- {
- cout<<str[0]<<"+"<<str[1]<<endl;
- cout<<str[0]<<endl;
- cout<<str[0]<<endl;
- return 0;
- }
- ll res = calcsum(1);
- string curstr = tostring(res); //out(res);
- int len = curstr.length();
- inwhich = 1;
- for(int i=len-1,j=1; j<=3 && i>=1; j++,i--)
- {
- mem(ar,0);
- mem(vis,0);
- lim = i;//cout<<lim<<""<<endl;
- backtrack(1,len,curstr);
- }
- res = calcsum(2);
- curstr = tostring(res);//out(res);
- if(fl) return 0;
- len = curstr.length();
- inwhich = 2;
- for(int i=len-1,j=1; j<=3 && i>=1; j++,i--)
- {
- mem(ar,0);
- mem(vis,0);
- lim = i;//cout<<lim<<""<<endl;
- backtrack(1,len,curstr);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement