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