View Code of Problem 22

// 巨菜的ACMer
#include <bits/stdc++.h>

using namespace std;
//-----
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i, l, r) for(int i=(l);i<(r);++i)
#define per(i, l, r) for(int i=(r)-1;i>=(l);--i)

//-----
ll powmod(ll x, ll k, ll p) {
    ll base = x % p, r = 1;
    for (; k; k >>= 1) {
        if (k & 1) r = r * base % p;
        base = base * base % p;
    }
    return r;
}

ll fermat(ll a, ll p) {
    return powmod(a, p - 2, p);
}

#define N 1005
char t1[N], t2[N], t[N];

void solve() {
    while (cin >> t1 >> t2) {
        int len1, len2;
        len1 = static_cast<int>(strlen(t1));
        len2 = static_cast<int>(strlen(t2));
        sort(t1, t1 + len1);
        sort(t2, t2 + len2);
        int e = -1;
        for (int x = 0, y = 0; x < len1 && y < len2;) {
            if (t1[x] == t2[y]) {
                if (e == -1 || t[e] != t1[x]) t[++e] = t1[x];
                x++;
                y++;
            } else if (t1[x] > t2[y]) {
                y++;
            } else {
                x++;
            }
        }
        t[++e] = '\0';
        cout << t << endl;
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}

Double click to view unformatted code.


Back to problem 22