Guest User

Untitled

a guest
Feb 15th, 2016
160
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.  
  10. set<string> res;
  11.         string s1;
  12.         string s2;
  13.  
  14. void go(int p1, int p2, string cur) {
  15.     if(p1 == s1.size() && p2 == s2.size()) {
  16.         res.insert(cur);
  17.         return;
  18.     }
  19.     if(p1 < s1.size()) {
  20.         go(p1 + 1, p2, cur + s1[p1]);
  21.     }
  22.     if(p2 < s2.size()) {
  23.         go(p1, p2 + 1, cur + s2[p2]);
  24.     }
  25. }
  26. int main()
  27. {
  28.     //freopen("input.txt","rt",stdin);
  29.     //freopen("output.txt","wt",stdout);
  30.     //freopen("console.in","rt",stdin);
  31.     //freopen("console.out","wt",stdout);
  32.  
  33.     int T;
  34.     scanf("%d", &T);
  35.     while(cin >> s1 >> s2) {
  36.         res.clear();
  37.         go(0, 0, "");
  38.         for(set<string>::iterator it = res.begin(); it != res.end(); it++)
  39.                 cout << *it << endl;
  40.         cout << endl;
  41.     }
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment