View Code of Problem 22

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

using namespace std;

/**
 * kkmd66 四刷
 * @return
 */

int main() {

    //两个不同的名字
    string name_1, name_2;
    while (getline(cin, name_1) && getline(cin, name_2)) {
        //依次遍历比对,相同的则把name_2对应的字符设置为'#',并将对应的字符存储
        multiset<char> multiset;
        for (int i = 0; i < name_1.size(); ++i) {
            for (int j = 0; j < name_2.size(); ++j) {
                if (name_1[i] == name_2[j]) {
                    name_2[j] = '#';
                    multiset.insert(name_1[i]);
                    break;
                }
            }
        }
        //输出
        for (auto i: multiset) {
            cout << i;
        }
        cout << endl;
    }

    return 0;
}

Double click to view unformatted code.


Back to problem 22