//Problem link>>http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2366
#include <bits/stdc++.h>
#define ll long long int
using namespace std ;
int main ()
{
ll n , i ,mn ,mx ,d, x ,op ,q ,v ;
char a[1000000] ;
while (cin>>n)
{
sprintf (a,"%lld",n) ;
ll len=strlen(a) ;
sort(a,a+len) ;
mx=0 ;
for (i=len-1 ; i>=0 ; i--)
{
mx=mx*10+(a[i]-'0') ;
}
op=0 , q ,v ;
for (i=0 ; i<len ; i++)
{
if (op==1) break ;
if (a[i]=='0' && op==0) continue ;
else
{
op=1 ;
q=i ;
v=a[i] ;
}
}
if (a[0]=='0')
{
a[0]=v ;
a[q]='0' ;
}
mn=0 ;
for (i=0 ; i<len ; i++)
{
mn=mn*10+(a[i]-'0') ;
}
d =mx-mn ;
x=d/9 ;
cout<<mx<<" - "<<mn<<" = "<<d<<" = "<<"9 * "<<x<<endl ;
}
return 0 ;
}
#include <bits/stdc++.h>
#define ll long long int
using namespace std ;
int main ()
{
ll n , i ,mn ,mx ,d, x ,op ,q ,v ;
char a[1000000] ;
while (cin>>n)
{
sprintf (a,"%lld",n) ;
ll len=strlen(a) ;
sort(a,a+len) ;
mx=0 ;
for (i=len-1 ; i>=0 ; i--)
{
mx=mx*10+(a[i]-'0') ;
}
op=0 , q ,v ;
for (i=0 ; i<len ; i++)
{
if (op==1) break ;
if (a[i]=='0' && op==0) continue ;
else
{
op=1 ;
q=i ;
v=a[i] ;
}
}
if (a[0]=='0')
{
a[0]=v ;
a[q]='0' ;
}
mn=0 ;
for (i=0 ; i<len ; i++)
{
mn=mn*10+(a[i]-'0') ;
}
d =mx-mn ;
x=d/9 ;
cout<<mx<<" - "<<mn<<" = "<<d<<" = "<<"9 * "<<x<<endl ;
}
return 0 ;
}
No comments:
Post a Comment