Submission

Status:

[PPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: blaboo123

Problemset: สตริงซ้ำซ้ำ

Language: cpp

Time: 0.003 second

Submitted On: 2026-10-06 14:10:37

#include <bits/stdc++.h>
using namespace std ;

set<char>kept ;
map<char,bool>mp ;
vector<char>v ;

int main() {
    ios_base::sync_with_stdio(0) ;
    cin.tie(0) ;
    string str1 , str2 ;
    cin >> str1 >> str2 ;
    if (str1.length() > str2.length()){
        for (auto ch : str1){
            kept.insert(ch) ;
            mp[ch] = 0 ;
        }
        for (auto d : str2){
            if (kept.find(d) != kept.end()){
                if (mp[d] == 0){
                    v.push_back(d) ;
                    mp[d] = 1 ;
                }
            }
        }
    }
    else {
        for (auto ch : str2){
            kept.insert(ch) ;
            mp[ch] = 0 ;
        }
        for (auto d : str1){
            if (kept.find(d) != kept.end()){
                if (mp[d] == 0){
                    v.push_back(d) ;
                    mp[d] = 1 ;
                }
            }
        }
    }
    for (auto ele : v){
        cout << ele << " " ;
    }
    return 0 ;
}