Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <string>
- using namespace std;
- int main()
- {
- int y, m=0, n=0, q=0, j=0, l, i, a=0;
- string x;
- cin >> x;
- q = x.length();
- int BIGGIE[q], SMALL[q], finalHIT[q];
- for(i=0; i<q; i++)
- {
- BIGGIE[i] = (int)x[i] - (int)'0';
- SMALL[i] = (int)x[i] - (int)'0';
- }
- sort(SMALL, SMALL + q);
- sort(BIGGIE, BIGGIE + q);
- reverse(BIGGIE, BIGGIE + q);
- for(i=q-1; i>=0; i--)
- {
- if(BIGGIE[i]<SMALL[i])
- {
- BIGGIE[i]+=10;
- BIGGIE[i-1]--;
- }
- finalHIT[i] = BIGGIE[i]-SMALL[i];
- }
- while(finalHIT[a]==0)
- {
- a++;
- if(a==q-1){
- cout << "0";
- return 0;
- }
- }
- for(i=a; i<q; i++)
- cout << finalHIT[i];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment