Advertisement
icatalin

CelMaiMicNr

Nov 12th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. int cmmnr(int x)
  8. {
  9.     int i=1,v[100],j,aux,n=0,nr=0,zero=0,cnr,ogl=0,ucifra;
  10.     while (x)
  11.     {
  12.         if (x%10==0)
  13.         zero++;
  14.         v[i]=x%10;
  15.         x/=10;
  16.         i++;
  17.         n++;
  18.     }
  19.  
  20.     for (i=1;i<=n-1;i++)
  21.         for (j=1;j<=n-1;j++)
  22.         if (v[j]>v[j+1])
  23.     {
  24.         aux=v[j];
  25.         v[j]=v[j+1];
  26.         v[j+1]=aux;
  27.     }
  28.  
  29.  
  30.  
  31.     for (i=1;i<=n;i++)
  32.         nr=nr*10+v[i];
  33.  
  34. // DE AICI INCOLO E PENTRU EXCEPTIA cu 0!
  35.  
  36. cnr=nr;
  37. while (cnr)
  38. {
  39.     ogl=ogl*10+cnr%10;
  40.     cnr=cnr/10;
  41.  
  42. }
  43. ucifra=ogl%10;
  44. ogl=ogl/10;
  45. ogl=ogl*pow(10,zero)+1;
  46. ogl=ogl*10+ucifra;
  47.  
  48. cnr=ogl;
  49.  
  50. ogl=0;
  51. while (cnr)
  52. {
  53.     ogl=ogl*10+cnr%10;
  54.     cnr=cnr/10;
  55. }
  56.  
  57.   return ogl;
  58. }
  59.  
  60.  
  61.  
  62. int main()
  63. {
  64.     cout<<cmmnr(95238050);
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement