UVA 11371 - Number Theory for Newbies Solution
Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long x,y,i,mx,mn,d,a;
string s,t;
while(cin>>s)
{
sort(s.begin(),s.end());
t=s;
if(t[0]=='0')
{
int len=t.size();
for(i=1; i<len; i++)
{
if(t[i]!='0')
{
swap(t[0],t[i]);
break;
}
}
}
reverse(s.begin(),s.end());
x=atoll(s.c_str());
y=atoll(t.c_str());
mx=max(x,y);
mn=min(x,y);
d=mx-mn;
a=d/9;
printf("%lld - %lld = %lld = 9 * %lld\n",mx,mn,d,a);
}
}
No comments