#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
string first, second;
int cnt1[26], cnt2[26];
while(getline(cin, first) && getline(cin, second)){
memset(cnt1, 0, sizeof(cnt1));
memset(cnt2, 0, sizeof(cnt2));
int sz1 = first.size(), sz2 = second.size();
for(int i = 0; i < sz1; i++)cnt1[first[i]-97]++;
for(int i = 0; i < sz2; i++)cnt2[second[i]-97]++;
for(int i = 0; i < 26; i++)
if(cnt1[i] > 0 && cnt2[i] > 0){
if(cnt1[i] < cnt2[i])for(int j = 1; j <= cnt1[i]; j++)printf("%c", i+97);
else for(int j = 1; j <= cnt2[i]; j++)printf("%c", i+97);
}
cout << endl;
}
return 0;
}
#include <cstdio>
#include <string>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
string first, second;
int cnt1[26], cnt2[26];
while(getline(cin, first) && getline(cin, second)){
memset(cnt1, 0, sizeof(cnt1));
memset(cnt2, 0, sizeof(cnt2));
int sz1 = first.size(), sz2 = second.size();
for(int i = 0; i < sz1; i++)cnt1[first[i]-97]++;
for(int i = 0; i < sz2; i++)cnt2[second[i]-97]++;
for(int i = 0; i < 26; i++)
if(cnt1[i] > 0 && cnt2[i] > 0){
if(cnt1[i] < cnt2[i])for(int j = 1; j <= cnt1[i]; j++)printf("%c", i+97);
else for(int j = 1; j <= cnt2[i]; j++)printf("%c", i+97);
}
cout << endl;
}
return 0;
}
No comments:
Post a Comment