Advertisement
a53

elim_m

a53
Nov 15th, 2021
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int A[25],X[25],m;
  5. long long x,n;
  6.  
  7. long long numar()
  8. {
  9. long long x=0;
  10. for(int i=1;i<=m;i++)
  11. x=x*10+A[X[i]];
  12. return x;
  13. }
  14.  
  15. void back(int k)
  16. {
  17. for(int i=X[k-1]+1;i<=n;i++)
  18. {
  19. X[k]=i;
  20. if(k==m)
  21. {
  22. long long nr=numar();
  23. if(nr>x) x=nr;
  24. }
  25. else back(k+1);
  26. }
  27. }
  28.  
  29. int main()
  30. {
  31. cin>>n>>m;
  32. int nc=0;
  33. while(n)
  34. {
  35. A[++nc]=n%10;
  36. n=n/10;
  37. }
  38. n=nc;
  39. for(int i=1,j=n;i<j;i++,j--)
  40. swap(A[i],A[j]);
  41. m=n-m;
  42. back(1);
  43. cout<<x;
  44. return 0;
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement