Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char strA[25], strB[25];
- int lenA, lenB;
- int ch[25];
- int id[25];
- int haveAns;
- void check() {
- int i, j, cnt, ans, printed;
- id[0] = 0;
- for (i = 1; i < lenA; i++) {
- id[i] = id[i - 1] + ch[i];
- }
- j = 0;
- ans = 1;
- for (i = 0; i < lenB; i++) {
- cnt = 0;
- while (id[j] == i) {
- cnt++;
- j++;
- }
- if (strB[i] != '#' && (cnt > 1 || strB[i] != strA[j - 1])) {
- ans = 0;
- }
- }
- if (ans == 1) {
- haveAns = 1;
- j = 0;
- printed = 0;
- for (i = 0; i < lenB; i++) {
- if (strB[i] != '#') {
- j++;
- continue;
- }
- if (printed) printf(" ");
- while (id[j] == i) {
- printf("%c", strA[j]);
- printed = 1;
- j++;
- }
- }
- printf("\n");
- }
- }
- void rec(int ind, int choosed) {
- if (ind == lenA) {
- if (choosed == lenB - 1) {
- check();
- }
- }else {
- if (choosed < lenB - 1) {
- ch[ind] = 1;
- rec(ind + 1, choosed + 1);
- }
- ch[ind] = 0;
- rec(ind + 1, choosed);
- }
- }
- int main() {
- scanf("%s %s", strA, strB);
- lenA = strlen(strA);
- lenB = strlen(strB);
- rec(1, 0);
- if (haveAns == 0) {
- printf("What the hack!?\n");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment