问大家个问题
vector<string> s1;
vector<string> s2;
假如s1是s2的超集,如果要把s1中不属于s2的部分取出来 怎么做好
什么方法都可以
1 #include<vector>
2 #include<string>
3 #include<algorithm>
4 #include<iterator>
5 #include<iostream>
6 using namespace std;
7
8 int main()
9 {
10 vector <string> s1;
11 vector <string> s2;
12 s1.push_back("1");
13 s1.push_back("2");
14 s1.push_back("3");
15
16 s2.push_back("1");
17 s2.push_back("2");
18 s2.push_back("3");
19 s2.push_back("4");
20 s2.push_back("5");
21 s2.push_back("6");
22
23 sort( s1.begin(),s1.end() );
24 sort( s2.begin(),s2.end() );
25 vector <string> out;
26 set_difference( s2.begin(),s2.end(),s1.begin(),s1.end() , back_inserter(out) );
27 copy(out.begin(),out.end(),ostream_iterator<string>( cout," " ) );
28 }