Guest User

Untitled

a guest
Feb 15th, 2016
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 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.         string s1, s2;
  32.  
  33. void go(int p1, int p2) {
  34.     if(p1 == sz(s1) && p2 == sz(s2)) {
  35.         string wtf = "";
  36.         for(int i = 0; i < p1 + p2; i++) {
  37.             wtf += cur[i];
  38.         }
  39.         res.pb(wtf);
  40.         return;
  41.     }
  42.     if(p1 < sz(s1)) {
  43.         cur[p1+p2] = s1[p1];
  44.         go(p1 + 1, p2);
  45.     }
  46.     if(p2 < sz(s2)) {
  47.         cur[p1+p2] = s2[p2];
  48.         go(p1, p2 + 1);
  49.     }
  50. }
  51.  
  52. int main()
  53. {
  54.     //freopen("input.txt","rt",stdin);
  55.     //freopen("output.txt","wt",stdout);
  56.     //freopen("console.in","rt",stdin);
  57.     //freopen("console.out","wt",stdout);
  58.  
  59.     int T;
  60.     scanf("%d", &T);
  61.     while(T--) {
  62.         cin >> s1 >> s2;
  63.         res.clear();
  64.         go(0, 0);
  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