"C++ 벡터 차집합"의 두 판 사이의 차이

1번째 줄: 1번째 줄:
==개요==
==개요==
;C++ 벡터 차집합
;C++ 벡터 차집합
[[파일:Venn0100.svg|120px]]


<syntaxhighlight lang='cpp' run>
<syntaxhighlight lang='cpp' run>

2024년 5월 29일 (수) 01:54 판

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 }}