hegemon88676

Atestat 3

Jan 17th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4.  
  5. int S1(int k)
  6. {
  7.     int maxi=0;
  8.     while(k>0)
  9.     {
  10.         if(k%10>maxi)
  11.             maxi=k%10;
  12.         k=k/10;
  13.     }
  14.     return maxi;
  15. }
  16.  
  17. int S2(int k, int c)
  18. {
  19.     int p=1,x=0;
  20.     while(k>0)
  21.     {
  22.         if(k%10!=c)
  23.         {
  24.             x=x+p*(k%10);
  25.             p=p*10;
  26.         }
  27.         k=k/10;
  28.     }
  29.     return x;
  30. }
  31.  
  32. int main()
  33. {
  34.     ifstream f("date.in");
  35.     int x,i,y,maxi;
  36.     while(f>>x)
  37.     {
  38.         y=0;
  39.         while(x>0)
  40.         {
  41.             maxi=S1(x);
  42.             y=y*10+maxi;
  43.             x=S2(x,maxi);
  44.         }
  45.         cout<<y<<" ";
  46.     }
  47. }
Add Comment
Please, Sign In to add comment