Guest User

Untitled

a guest
Feb 15th, 2016
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 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. string s1, s2;
  11.  
  12. void go(int p1, int p2, string cur) {
  13.     if(p1 == s1.size() && p2 == s2.size()) {
  14.         res.insert(cur);
  15.         return;
  16.     }
  17.     if(p1 < s1.size()) {
  18.         go(p1 + 1, p2, cur + s1[p1]);
  19.     }
  20.     if(p2 < s2.size()) {
  21.         go(p1, p2 + 1, cur + s2[p2]);
  22.     }
  23. }
  24. int main()
  25. {
  26.     //freopen("input.txt","rt",stdin);
  27.     //freopen("output.txt","wt",stdout);
  28.     //freopen("console.in","rt",stdin);
  29.     //freopen("console.out","wt",stdout);
  30.  
  31.     int T;
  32.     scanf("%d", &T);
  33.     while(T--) {
  34.         cin >> s1 >> s2;
  35.         res.clear();
  36.         go(0, 0, "");
  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. }
Add Comment
Please, Sign In to add comment