#include <bits/stdc++.h> using namespace std; int main(){ int n=0; cin>>n; while(n--){ string a; cin >>a; string b; cin>>b; string c; if(a.size()>b.size()){ swap(a,b); } for(int i=0;i<a.size();i++){ for(int j=0;j<b.size();j++){ if(a[i]==b[j]){ c.push_back(b[j]); b[j]=' '; break; } } } if(c.empty()){ cout <<"-1"<<endl; } else{ sort(c.begin(),c.end()); cout<<c<<endl; } } return 0; } |
Double click to view unformatted code.