Advertisement
Guest User

Untitled

a guest
Feb 15th, 2016
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <vector>
  4. #include <string>
  5. #include <algorithm>
  6. #include <set>
  7. using namespace std;
  8.  
  9. set<string> res;
  10.  
  11. void go(int p1, string s1, int p2, string s2, string cur) {
  12.     if(p1 == s1.size() && p2 == s2.size()) {
  13.         res.insert(cur);
  14.         return;
  15.     }
  16.     if(p1 < s1.size()) {
  17.         go(p1 + 1, s1, p2, s2, cur + s1[p1]);
  18.     }
  19.     if(p2 < s2.size()) {
  20.         go(p1, s1, p2 + 1, s2, cur + s2[p2]);
  21.     }
  22. }
  23. int main()
  24. {
  25.     //freopen("input.txt","rt",stdin);
  26.     //freopen("output.txt","wt",stdout);
  27.     //freopen("console.in","rt",stdin);
  28.     //freopen("console.out","wt",stdout);
  29.  
  30.     int T;
  31.     scanf("%d", &T);
  32.     while(T--) {
  33.         string s1, s2;
  34.         cin >> s1 >> s2;
  35.         res.clear();
  36.         go(0, s1, 0, s2, "");
  37.         for(set<string>::iterator it = res.begin(); it != res.end(); it++)
  38.                 cout << *it << endl;
  39.         cout << endl;
  40.     }
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement