Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int cmmnr(int x)
- {
- int i=1,v[100],j,aux,n=0,nr=0,zero=0,cnr,ogl=0,ucifra;
- while (x)
- {
- if (x%10==0)
- zero++;
- v[i]=x%10;
- x/=10;
- i++;
- n++;
- }
- for (i=1;i<=n-1;i++)
- for (j=1;j<=n-1;j++)
- if (v[j]>v[j+1])
- {
- aux=v[j];
- v[j]=v[j+1];
- v[j+1]=aux;
- }
- for (i=1;i<=n;i++)
- nr=nr*10+v[i];
- // DE AICI INCOLO E PENTRU EXCEPTIA cu 0!
- cnr=nr;
- while (cnr)
- {
- ogl=ogl*10+cnr%10;
- cnr=cnr/10;
- }
- ucifra=ogl%10;
- ogl=ogl/10;
- ogl=ogl*pow(10,zero)+1;
- ogl=ogl*10+ucifra;
- cnr=ogl;
- ogl=0;
- while (cnr)
- {
- ogl=ogl*10+cnr%10;
- cnr=cnr/10;
- }
- return ogl;
- }
- int main()
- {
- cout<<cmmnr(95238050);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement