C++ 벡터 차집합

1 개요[ | ]

C++ 벡터 차집합

Venn0100.svg

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    vector<string> v1 = {"A","B","C","D"};
    vector<string> v2 = {"C","D","E","F"};
    
    vector<string> v(v1.size()+v2.size());
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    set_difference(v1.begin(), v1.end(), v2.begin(), v2.end(), v.begin());
    for(const auto& el: v) cout << el << ' '; // A B 
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}