#include <iostream>
#include <cstdio>
#include <string.h>
#include <stack>
using namespace std;
#define size 20
char str1[size],str2[size];
char resultstr[size ];
bool resultbool[size * 2];
void printf_p()
{
int i;
for( i = 0;i < strlen(str1) *2 ; i++)
{
if(resultbool[i])printf("i ");
else printf("o ");
}
printf("\n");
}
void dfs(int i, int lenth ,int nchar)
{
if(nchar * 2 > lenth ) return;
if(i == lenth)
{
int j = 0 , k = 0,m=0;
stack <char> S;
for( j = 0; j < lenth ; j++)
{
if(resultbool[j] == 1) S.push(str1[k++]);
else if(S.empty())return;
else
{
resultstr[m++] = S.top();
S.pop();
}
}
if(strcmp(resultstr,str2) == 0)
printf_p();
return;
}
resultbool[i] = 1;
dfs(i + 1 , lenth,nchar+1);
resultbool[i] = 0 ;
dfs(i+1,lenth,nchar);
}
int main()
{
int lenth;
while (~scanf("%s %s", str1,str2))
{
printf("[\n");
if( (lenth =strlen(str1) ) != strlen(str2))
{
printf("]\n");
continue;
}
memset(resultstr,0,sizeof(resultstr));
memset(resultbool,0,sizeof(resultbool));
dfs(0,lenth * 2,0);
printf("]\n");
}
return 0;
}
zju1004 dfs
最新推荐文章于 2019-03-03 18:15:06 发布