Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <set>
- using namespace std;
- set<string> res;
- string s1, s2;
- void go(int p1, int p2, string cur) {
- if(p1 == s1.size() && p2 == s2.size()) {
- res.insert(cur);
- return;
- }
- if(p1 < s1.size()) {
- go(p1 + 1, p2, cur + s1[p1]);
- }
- if(p2 < s2.size()) {
- go(p1, p2 + 1, cur + s2[p2]);
- }
- }
- 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, "");
- for(set<string>::iterator it = res.begin(); it != res.end(); it++)
- cout << *it << endl;
- cout << endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment