View Code of Problem 22

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    string str1;
    string str2;
    while (cin >> str1) {
        cin >> str2;
        
        vector<char> result;

        for (int i = 0; i < str1.length(); ++i) {
            if (str2.find(str1[i]) != string::npos){
                result.push_back(str1[i]);
            }
        }

        sort(result.begin(),result.end());
        for (int i = 0; i < result.size(); ++i) {
            cout << result[i];
        }
        cout << endl;
    }
}

Double click to view unformatted code.


Back to problem 22