velimir

Odzemanje

Mar 22nd, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. using namespace std;
  5. int main()
  6. {
  7.     int y, m=0, n=0, q=0, j=0, l, i, a=0;
  8.     string x;
  9.     cin >> x;
  10.     q = x.length();
  11.     int BIGGIE[q], SMALL[q], finalHIT[q];
  12.     for(i=0; i<q; i++)
  13.     {
  14.         BIGGIE[i] = (int)x[i] - (int)'0';
  15.         SMALL[i] = (int)x[i] - (int)'0';
  16.     }
  17.     sort(SMALL, SMALL + q);
  18.     sort(BIGGIE, BIGGIE + q);
  19.     reverse(BIGGIE, BIGGIE + q);
  20.  
  21.     for(i=q-1; i>=0; i--)
  22.     {
  23.         if(BIGGIE[i]<SMALL[i])
  24.         {
  25.             BIGGIE[i]+=10;
  26.             BIGGIE[i-1]--;
  27.         }
  28.         finalHIT[i] = BIGGIE[i]-SMALL[i];
  29.     }
  30.     while(finalHIT[a]==0)
  31.     {
  32.         a++;
  33.         if(a==q-1){
  34.             cout << "0";
  35.             return 0;
  36.         }
  37.     }
  38.     for(i=a; i<q; i++)
  39.         cout << finalHIT[i];
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment