-
//zoj1004 Anagrams by Stack
-
//Accepted 1004 C ++ 00:00.00 860K
-
#include <cstdio>
-
#include <iostream>
-
#include <string>
-
#include <stack>
-
using namespace std;
-
string s,t;
-
string ans;
-
int len,sp,tp,lena;
-
void dfs(stack< char > st)
-
{
-
if (tp==len){
-
for (int i=0; i<lena; ++i)
-
cout << ans[i] << ' ';
-
cout << endl;
-
return ;
-
}
-
if (sp<len){
-
st.push(s[sp++]);
-
ans[lena++] = 'i';
-
dfs(st);
-
lena--;
-
sp--;
-
st.pop();
-
}
-
char c;
-
if (!st.empty() && (c=st.top())==t[tp]){
-
st.pop();
-
tp++;
-
ans[lena++] = 'o';
-
dfs(st);
-
lena--;
-
tp--;
-
st.push(c);
-
}
-
}
-
void solve()
-
{
-
cout << '[' << endl;
-
if ((len=s.length())==t.length()){
-
sp = tp = lena = 0;
-
stack< char > st;
-
dfs(st);
-
}
-
cout << ']' << endl;
-
}
-
int main()
-
{
-
#ifdef ONLINE_JUDGE
-
#else
-
freopen("1004.txt","r",stdin);
-
#endif
-
while (cin >> s >> t)
-
solve();
-
#ifdef ONLINE_JUDGE
-
#else
-
fclose(stdin);
-
#endif
-
return 0;
-
}
zoj1004 Anagrams by Stack
最新推荐文章于 2018-05-25 16:23:53 发布