ValerianBenchea

Ordinarea cifrelor a n numere

Dec 2nd, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int c0, c1, c2, c3, c4, c5, c6, c7, c8, c9;
  5. int main()
  6. {
  7.     int n, c, x, i;
  8.     cout<<"n="; cin>>n;
  9.     for(i=1; i<=n; i++)
  10.     {
  11.         cin>>x;
  12.         while(x!=0)
  13.         {
  14.             c=x%10;
  15.             if(c==0)
  16.                 c0++;
  17.  
  18.             if(c==1)
  19.                 c1++;
  20.  
  21.             if(c==2)
  22.                 c2++;
  23.  
  24.             if(c==3)
  25.                 c3++;
  26.  
  27.             if(c==4)
  28.                 c4++;
  29.  
  30.             if(c==5)
  31.                 c5++;
  32.  
  33.             if(c==6)
  34.                 c6++;
  35.  
  36.             if(c==7)
  37.                 c7++;
  38.  
  39.             if(c==8)
  40.                 c8++;
  41.  
  42.             if(c==9)
  43.                 c9++;
  44.  
  45.             x=x/10;
  46.         }
  47.     }
  48.     for(i=1; i<=c0; i++)
  49.         cout<<0<<" ";
  50.  
  51.     for(i=1; i<=c1; i++)
  52.         cout<<1<<" ";
  53.  
  54.     for(i=1; i<=c2; i++)
  55.         cout<<2<<" ";
  56.  
  57.     for(i=1; i<=c3; i++)
  58.         cout<<3<<" ";
  59.  
  60.     for(i=1; i<=c4; i++)
  61.         cout<<4<<" ";
  62.  
  63.     for(i=1; i<=c5; i++)
  64.         cout<<5<<" ";
  65.  
  66.     for(i=1; i<=c6; i++)
  67.         cout<<6<<" ";
  68.  
  69.     for(i=1; i<=c7; i++)
  70.         cout<<7<<" ";
  71.  
  72.     for(i=1; i<=c8; i++)
  73.         cout<<8<<" ";
  74.  
  75.     for(i=1; i<=c9; i++)
  76.         cout<<9<<" ";
  77.  
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment