SHARE
TWEET

ASD Pb 7 elim cifre

madalinaradu May 26th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** p7 eliminare cifre */
  2. #include<iostream>
  3. using namespace std;///nu functioneaza
  4.  
  5. int n=3452234, a[20], x[20], maxim, k=4;///a[] valorile corespondente elementelor tabloului de pozitii x[].
  6.  
  7. int numar(int a[20], int x[20], int c){
  8.     int nr=0;
  9.     for(int i=1; i<=c; i++){
  10.         nr = nr * 10 + a[x[i]];
  11.     }
  12.     return nr;
  13. }
  14. void bkt(int k, int c){                   ///c=n-k
  15.     for(int i=n; i>=1; i--){
  16.         if(i<x[k-1] || k==1){
  17.             x[k]=i;
  18.             if(k==c){
  19.                 int nr=numar(a,x,c);
  20.                 if(nr>maxim)
  21.                     maxim=nr;
  22.             }else bkt(k+1,c);
  23.         }
  24.     }
  25. }
  26. int main(){
  27.     int i=0;
  28.     while(n){
  29.         a[++i]=n%10;
  30.         n=n/10;
  31.     }
  32.     n=i;
  33.     bkt(1,n-k);
  34.     cout<<maxim;
  35.     return 0;
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top