微信公众号推广链接,商城类网站怎么优化,丰县微网站开发,近期时政热点新闻20条Anagrams by Stack 题目链接#xff1a;http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId4 题目大意#xff1a;输入两个字符串序列#xff0c;判断能否通过对第一个字符串进行进栈出栈操作得到第二个字符串#xff0c;若能则输出所有能达到的进出栈操作过程。…Anagrams by Stack 题目链接http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId4 题目大意输入两个字符串序列判断能否通过对第一个字符串进行进栈出栈操作得到第二个字符串若能则输出所有能达到的进出栈操作过程。我通过全排列每得到一组操作过程则用函数按照这个操作过程判断能否得到第二个字符串若能则表明此操作过程可行输出。 代码如下 1 # includeiostream2 # includestack3 # includevector4 # includealgorithm5 using namespace std;6 7 string str1,str2;8 stackchar p;9 vectorchar ans;
10 int len;
11
12 void print(){
13 for(int i 0; ians.size(); i)
14 coutans[i] ; //注意空格
15 coutendl;
16 }
17
18 void dfs(int x,int y){
19 if(xlen ylen)
20 print();
21 if(x1len){
22 p.push(str1[x]);
23 ans.push_back(i);
24 dfs( x1 , y);
25 p.pop();
26 ans.pop_back();
27 }
28 if(y1x y1len p.top() str2[y]){
29 char temp p.top();
30 p.pop();
31 ans.push_back(o);
32 dfs(x,y1);
33 p.push(temp);
34 ans.pop_back();
35 }
36 }
37
38 int main(){
39 while(cin str1 str2){
40 len str1.length();
41 string t1 str1, t2 str2;
42 sort(t1.begin(),t1.end());
43 sort(t2.begin(),t2.end());
44 cout[endl;
45 if(t1 t2){
46 dfs(0,0);
47 }
48 cout]endl;
49 }
50 return 0;
51 } 转载于:https://www.cnblogs.com/acm-bingzi/p/3258815.html