Advertisement
STANAANDREY

sda flag

Jan 5th, 2024
1,147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define N_COLS 6
  5. const char* COLORS[] = {"white", "yellow", "red", "green", "blue", "black"};
  6. #define N 3
  7. int flag[N];
  8.  
  9. void printFlag() {
  10.     for (int i = 0; i < N; i++) {
  11.         printf("%s ", COLORS[flag[i]]);
  12.     }
  13.     putchar('\n');
  14. }
  15.  
  16. void bktr(int k) {
  17.     if (k == N) {//sol
  18.         if (flag[0] == flag[1] || flag[1] == flag[2] || flag[0] == flag[2]) {
  19.             return;
  20.         }
  21.         printFlag();
  22.         return;
  23.     }
  24.     if (k == 1) {
  25.         flag[k] = 1;
  26.         bktr(k + 1);
  27.         flag[k] = 3;
  28.         bktr(k + 1);
  29.         return;
  30.     }//*/
  31.     for (int i = 0; i < N_COLS; i++) {
  32.         flag[k] = i;
  33.         bktr(k + 1);
  34.     }
  35. }
  36.  
  37. int main(void) {
  38.     bktr(0);
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement