#include #include using namespace std; // Check all assignments of letters in C to A and B and determine // if C is composed of A and B "shuffled together" (in order, but merged.) string isMerge(string A, string B, string C, unsigned int a, unsigned int b, unsigned int c) { // If we've looked through all of all three words if (a == A.size() and b == B.size() and c == C.size()) return C; // Give preference to A if (A[a] == C[c]) { // Assume C[c] comes from A, so uppercase it C[c] = toupper(C[c]); // Check string ret = isMerge(A, B, C, a + 1, b, c + 1); // If we get a valid merge, then return it if (ret != "*** NOT A MERGE ***") return ret; // We were wrong, fix it C[c] = tolower(C[c]); } // Check b. Note this isn't an else if. if (B[b] == C[c]) { return isMerge(A, B, C, a, b + 1, c + 1); } // If we cant match the current character of C, we're done. return "*** NOT A MERGE ***"; } int main() { // Simplest input ever. string a; string b; string c; while (cin >> a >> b >> c) { cout << isMerge(a, b, c, 0, 0, 0) << endl; } }