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

(새 문서: ==개요== ;C++ 벡터 차집합 <syntaxhighlight lang='cpp' run> #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { vector<string> v1...)
 
13번째 줄: 13번째 줄:
      
      
     vector<string> v(v1.size()+v2.size());
     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());
     set_difference(v1.begin(), v1.end(), v2.begin(), v2.end(), v.begin());
     for(const auto& el: v) cout << el << ' '; // A B  
     for(const auto& el: v) cout << el << ' '; // A B  
}
}
</syntaxhighlight>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2023년 12월 26일 (화) 01:11 판

1 개요

C++ 벡터 차집합
#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 }}