View Code of Problem 2591

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main(){
	char ch[1000];
	char ch1[1000];
	int cnt[256];
	char k[1000];
	int t;
	int T;
	scanf("%d", &T );
	while( T-- ){
		t = 0;
		memset( cnt, 0, sizeof(int)*256 );
		scanf("%s %s", &ch, &ch1 );
		for( int i=0; i<strlen(ch); i++ ){
		    cnt[ch[i]]++;
	  }
	   for( int i=0; i<strlen(ch1); i++ ){
	   		if( cnt[ch1[i]] != 0 ){
	   			k[t++] = ch1[i];
				cnt[ch1[i]]--;	
	     }
	   }
	   k[t] = '\0';
	   sort(k,k+t);
	   if( t== 0 ){
	   	  printf("-1\n");
	   }else{
	   	  puts(k);
	   }
	}
	return 0;
	
}

Double click to view unformatted code.


Back to problem 2591