View Code of Problem 2591

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main()
{
    string str1, str2;
    int n;
    cin >> n;
    while (n--)
    {
        int flag = 1;
        cin >> str1;
        cin >> str2;
        int cnt[3][26] = {0};
        for (int i = 0; i < str1.size(); i++)
            cnt[0][str1[i] - 'A']++;
        for (int i = 0; i < str2.size(); i++)
            cnt[1][str2[i] - 'A']++;
        for (int i = 0; i < 26; i++)
            for (int j = 0; j < min(cnt[0][i], cnt[1][i]); j++){
                flag = 0;
                printf("%c", 'A' + i);
            }
        if(flag)
            printf("-1");
        printf("\n");
    }
}

Double click to view unformatted code.


Back to problem 2591