samuel21119

12987 - Let's build a hacker script LONG

Nov 22nd, 2020
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char strA[25], strB[25];
  6. int lenA, lenB;
  7. int ch[25];
  8. int id[25];
  9. int haveAns;
  10.  
  11. void check() {
  12.     int i, j, cnt, ans, printed;
  13.     id[0] = 0;
  14.     for (i = 1; i < lenA; i++) {
  15.         id[i] = id[i - 1] + ch[i];
  16.     }
  17.     j = 0;
  18.     ans = 1;
  19.     for (i = 0; i < lenB; i++) {
  20.         cnt = 0;
  21.         while (id[j] == i) {
  22.             cnt++;
  23.             j++;
  24.         }
  25.         if (strB[i] != '#' && (cnt > 1 || strB[i] != strA[j - 1])) {
  26.             ans = 0;
  27.         }
  28.     }
  29.     if (ans == 1) {
  30.         haveAns = 1;
  31.         j = 0;
  32.         printed = 0;
  33.         for (i = 0; i < lenB; i++) {
  34.             if (strB[i] != '#') {
  35.                 j++;
  36.                 continue;
  37.             }
  38.             if (printed) printf(" ");
  39.             while (id[j] == i) {
  40.                 printf("%c", strA[j]);
  41.                 printed = 1;
  42.                 j++;
  43.             }
  44.         }
  45.         printf("\n");
  46.     }
  47. }
  48.  
  49. void rec(int ind, int choosed) {
  50.     if (ind == lenA) {
  51.         if (choosed == lenB - 1) {
  52.             check();
  53.         }
  54.     }else {
  55.         if (choosed < lenB - 1) {
  56.             ch[ind] = 1;
  57.             rec(ind + 1, choosed + 1);
  58.         }
  59.         ch[ind] = 0;
  60.         rec(ind + 1, choosed);
  61.     }
  62. }
  63.  
  64. int main() {
  65.     scanf("%s %s", strA, strB);
  66.     lenA = strlen(strA);
  67.     lenB = strlen(strB);
  68.     rec(1, 0);
  69.     if (haveAns == 0) {
  70.         printf("What the hack!?\n");
  71.     }
  72.     return 0;
  73. }
  74.  
Add Comment
Please, Sign In to add comment