#include <stdio.h> #include <iostream> #include <string.h> #include <string> #include <algorithm> #include <iomanip> using namespace std; int main() { string s1; string s2; while (getline(cin, s1)) { getline(cin, s2); int a1[26] = {0}; int a2[26] = {0}; for (int i = 0; i < s1.length(); i++) { a1[s1[i] - 'a']++; } for (int i = 0; i < s2.length(); i++) { a2[s2[i] - 'a']++; } for (int i = 0; i < 26; i++) { if (a1[i]!=0&&a2[i]!=0) { int m = min(a1[i], a2[i]); while (m--) { cout <<(char) (i + 'a'); } } } cout << endl; } return 0; } |
Double click to view unformatted code.