View Code of Problem 2591

#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int T;
	cin>>T;
	while(T--){
		string str1;
		string str2;
		string s="";
		cin>>str1;
		cin>>str2;
		for(int i=0;i<str2.length();i++){
			if(str1.find(str2[i])!=str1.npos){
				s+=str2[i];
				str1.erase(str1.find(str2[i]),1);
			}
		}
		if(s.size()==0){
			cout<<-1<<endl;
		}
		else{
			sort(s.begin(),s.end());
			cout<<s<<endl;
		}
	}
}

Double click to view unformatted code.


Back to problem 2591