Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <list>
- #include <map>
- #include <set>
- #include <stdlib.h>
- #include <sstream>
- #include <assert.h>
- #include <memory.h>
- #include <string.h>
- #include <time.h>
- using namespace std;
- #pragma comment(linker, "/STACK:100000000")
- #define mp make_pair
- #define pb push_back
- #define ll long long
- #define ull long long
- #define sz(x) (int)(x).size()
- vector<string> res;
- char cur[100100];
- string s1, s2;
- void go(int p1, int p2) {
- if(p1 == sz(s1) && p2 == sz(s2)) {
- string wtf = "";
- for(int i = 0; i < p1 + p2; i++) {
- wtf += cur[i];
- }
- res.pb(wtf);
- return;
- }
- if(p1 < sz(s1)) {
- cur[p1+p2] = s1[p1];
- go(p1 + 1, p2);
- }
- if(p2 < sz(s2)) {
- cur[p1+p2] = s2[p2];
- go(p1, p2 + 1);
- }
- }
- int main()
- {
- //freopen("input.txt","rt",stdin);
- //freopen("output.txt","wt",stdout);
- //freopen("console.in","rt",stdin);
- //freopen("console.out","wt",stdout);
- int T;
- scanf("%d", &T);
- while(T--) {
- cin >> s1 >> s2;
- res.clear();
- go(0, 0);
- sort(res.begin(), res.end());
- for(int i = 0; i < sz(res); i++) {
- if(!i || res[i] != res[i-1])
- puts(res[i].c_str());
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment