SHARE
TWEET

ASD Pb 8 perm fixe

madalinaradu May 26th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** p8 permutari elemente pare fixe */
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<conio.h>
  5.  
  6.  
  7. int sol[20], n = 6;//globale
  8. void afisare() {
  9.     for (int i = 1; i <= n; i++) {
  10.         printf("%3d", sol[i]);
  11.     }
  12.     printf("\n");
  13. }
  14.  
  15. //pozitiile pare raman neschimbate
  16. int valid3(int k) {// sau bool
  17.     for (int i = 1; i < k; i++) {
  18.         if (sol[k] == sol[i])
  19.             return 0;
  20.     }
  21.  
  22.     if (k % 2 == 1 && sol[k] != k)
  23.         return 0;
  24.     return 1;
  25. }
  26.  
  27. void bkt(int k) {
  28.  
  29.     for (int i = 1;i <= n;i++) {
  30.         sol[k] = i;
  31.         if (valid3(k)) {
  32.             if (k == n) {
  33.  
  34.                 afisare();
  35.             }
  36.  
  37.             else bkt(k + 1);
  38.         }
  39.     }
  40. }
  41.  
  42. //cresc desc adaugam conditii, conditii de unicitate si cond ca pana la jum sa fie cresc/descresc si invers
  43. int main() {
  44.  
  45.  
  46.     bkt(1);
  47.     printf("-------");
  48.  
  49.     _getch();
  50.     return 0;
  51. }
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