#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; int main() { int t,i,j; scanf("%d",&t); while(t--) { char a[100],b[100],c[100]; scanf("%s %s",&a,&b); int k=0; for(i=0;i<strlen(a);i++) { for(j=0;j<strlen(b);j++) { if(a[i]==b[j]) { c[k++]=a[i]; b[j]='#'; break; } } } c[k]='\0'; sort(c,c+k); if(k==0) printf("-1\n"); else puts(c); } return 0; } |
Double click to view unformatted code.