View Code of Problem 2591

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
    int t,k;
    cin>>t;
    string a,b;
    char c[999];
    while(t--){
        k=0;
        cin>>a>>b;
        memset(c,0,sizeof(c));
        for(int i=0;i<a.length();i++){
            for(int j=0;j<b.length();j++){
                if(a[i]==b[j]){
                    c[k++]=a[i];
                    b[j]='*';
                    break;
                }
            }
        }
        if(k==0)
            cout<<-1<<endl;
        else{
            sort(c,c+k);
            for(int i=0;i<k;i++){
                cout<<c[i];
            }
            cout<<endl;
        }
    }
    return 0;
}









/*
Main.cc: In function 'int main()':
Main.cc:14:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<a.length();i++){
                      ^
Main.cc:15:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=0;j<b.length();j++){
                          ^
Main.cc:26:23: error: 'sort' was not declared in this scope
             sort(c,c+k);
                       ^
*/

Double click to view unformatted code.


Back to problem 2591