Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.0 kB
3
Indexable
Never
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char s[21], p[21], ans[21];
int lens, lenp, tmp = 0;

void solve(int index_s, int index_p, int pos){
    if(index_s == lens && index_p == lenp){
        tmp = 1;
        for(int i = 0; i < pos; i++){
            if(i == pos-1 && ans[i] == ' ') break;
            //有可能最後一個字元是空格
            else printf("%c", ans[i]);
        }
        printf("\n");
        return;
    }
    if(index_s == lens || index_p == lenp) return;
    if(p[index_p] == '#'){
        ans[pos] = s[index_s];
        pos = pos + 1;
        ans[pos] = ' ';
        solve(index_s+1, index_p+1, pos+1);//上下兩者的順序不可掉換
        solve(index_s+1, index_p, pos);
    }
    else{
        if(s[index_s] == p[index_p]) solve(index_s+1, index_p+1, pos);
        else return;
    }
}

int main(){

    scanf("%s %s",s,p);
    
    lens = strlen(s);
    lenp = strlen(p);
    solve(0, 0, 0);
    if(tmp == 0) printf("What the hack!?\n");
}