Guest User

Untitled

a guest
Feb 15th, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <string>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <vector>
  7. #include <queue>
  8. #include <list>
  9. #include <map>
  10. #include <set>
  11. #include <stdlib.h>
  12. #include <sstream>
  13. #include <assert.h>
  14. #include <memory.h>
  15. #include <string.h>
  16. #include <time.h>
  17.  
  18. using namespace std;
  19.  
  20. #pragma comment(linker, "/STACK:100000000")
  21.  
  22. #define mp make_pair
  23. #define pb push_back
  24. #define ll long long
  25. #define ull long long
  26. #define sz(x) (int)(x).size()
  27.  
  28. vector<string> res;
  29.  
  30. char cur[100100];
  31.  
  32. void go(int p1, string &s1, int p2, string &s2) {
  33.     if(p1 == sz(s1) && p2 == sz(s2)) {
  34.         string wtf = "";
  35.         for(int i = 0; i < p1 + p2; i++) {
  36.             wtf += cur[i];
  37.         }
  38.         res.pb(wtf);
  39.         return;
  40.     }
  41.     if(p1 < sz(s1)) {
  42.         cur[p1+p2] = s1[p1];
  43.         go(p1 + 1, s1, p2, s2);
  44.     }
  45.     if(p2 < sz(s2)) {
  46.         cur[p1+p2] = s2[p2];
  47.         go(p1, s1, p2 + 1, s2);
  48.     }
  49. }
  50.  
  51. int main()
  52. {
  53.     //freopen("input.txt","rt",stdin);
  54.     //freopen("output.txt","wt",stdout);
  55.     //freopen("console.in","rt",stdin);
  56.     //freopen("console.out","wt",stdout);
  57.  
  58.     int T;
  59.     scanf("%d", &T);
  60.     while(T--) {
  61.         string s1, s2;
  62.         cin >> s1 >> s2;
  63.         res.clear();
  64.         go(0, s1, 0, s2);
  65.         sort(res.begin(), res.end());
  66.         for(int i = 0; i < sz(res); i++) {
  67.             if(!i || res[i] != res[i-1])
  68.                 puts(res[i].c_str());
  69.         }
  70.         cout << endl;
  71.     }
  72.  
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment