/* File: 10252.cpp Author: ACboy Date: 2010-3-29 Result: 1A Descripition: UVa 10252 Common Permutation */ #include <iostream> #include <algorithm> using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("10252.txt", "r", stdin); #endif char ans[1010]; char str[2][1010]; while (gets(str[0]), gets(str[1])) { sort(str[0], str[0] + strlen(str[0])); sort(str[1], str[1] + strlen(str[1])); int i, j; int len0 = strlen(str[0]); int len1 = strlen(str[1]); i = j = 0; int c = 0; while (i < len0 && j < len1) { if (str[0][i] > str[1][j]) { j++; } else if (str[0][i] < str[1][j]) { i++; } else { ans[c++] = str[0][i]; i++; j++; } } ans[c] = '/0'; cout << ans << endl; } return 0; }