View Code of Problem 2591

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
    int T;
    cin>>T;
    while(T--){
        char a[999],b[999],c[999]={0};
        cin>>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]){
                    c[k++]=b[j];
                    b[j]='#';
                    break;
                }
                }
        }
        if(k==0){
            cout<<"-1"<<endl;
        }
        else{
        sort(c,c+k);
        cout<<c;
        cout<<endl;
        }
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 2591