View Code of Problem 22

#include <iostream>
#include "string"
#include "set"

using namespace std;

int main() {

    string str1, str2;
    while (getline(cin, str1) && getline(cin, str2)) {

        //遍历,记录
        multiset<char> result;
        for (int i = 0; i < str1.size(); ++i) {
            if (str2.find(str1[i]) != -1) {
                result.insert(str1[i]);
                str2[str2.find(str1[i])] = '#';
            }
        }

        //输出
        for (auto it: result) {
            cout << it;
        }
        cout << endl;
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 22