Skip to content

Instantly share code, notes, and snippets.

/main.cxx Secret

Created February 15, 2016 16:29
Show Gist options
  • Save anonymous/0d56a7c8a91601006153 to your computer and use it in GitHub Desktop.
Save anonymous/0d56a7c8a91601006153 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <sstream>
using namespace std;
set<string> res;
void go(int p1, string s1, int p2, string s2, string cur) {
if(p1 == s1.size() && p2 == s2.size()) {
res.insert(cur);
return;
}
if(p1 < s1.size()) {
go(p1 + 1, s1, p2, s2, cur + s1[p1]);
}
if(p2 < s2.size()) {
go(p1, s1, p2 + 1, s2, cur + s2[p2]);
}
}
int main()
{
int T;
scanf("%d", &T);
while(T--) {
res.clear();
char b1[100], b2[100];
scanf("%s %s", b1, b2);
go(0, string(b1), 0, string(b2), "");
for(set<string>::iterator it = res.begin(); it != res.end(); it++)
cout << *it << endl;
cout << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment