Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int x[10], maxx;
- int numar(int a[10], int x[10], int c)
- {
- int nr = 0;
- for (int i = 0; i < c; i++)
- nr = nr * 10 + a[x[i]];
- return nr;
- }
- void back(int k, int c, int a[], int n)
- {
- if (k == c)
- {
- int nr = numar(a, x, c);
- if (nr > maxx) maxx = nr;
- }
- for (int i = n - 1; i >= 0; i--)
- if ((k - 1 >= 0 && i < x[k - 1]) || k == 0)
- {
- x[k] = i;
- if (k < c)
- back(k + 1, c, a, n);
- }
- }
- int main()
- {
- int n, a[10], k;
- cin >> n >> k;
- int i = 0;
- while (n)
- {
- a[++i] = n % 10;
- n = n / 10;
- }
- n = i;
- back(0, n - k, a, n);
- cout << maxx;
- return 0;
- }
Add Comment
Please, Sign In to add comment