#include <iostream>
#include <vector>
using namespace std;
bool same_vec(vector<int> a, vector<int> b)
{
for(int i=0; i<b.size(); i++)
{
if(find(a.begin(), a.end(), b[i]) == a.end())
return false;
}
return true;
}
int main()
{
// define two vector
vector<int> vect1;
vector<int> vect2;
cout << "Please enter the first vector elements: " << endl;
int value;
while(cin>>value)
{
vect1.push_back(value);
if(cin.get()=='\n')
break;
}
cout << "Please enter the second vector elements: " << endl;
while(cin>>value)
{
vect2.push_back(value);
if(cin.get()=='\n')
break;
}
cout<< "The first vector: ";
for(int i=0; i<vect1.size(); i++){
cout << vect1[i] << ",";
}
cout << endl;
cout<< "The second vector: ";
for(int i=0; i<vect2.size(); i++){
cout << vect2[i] << ",";
}
cout << endl;
bool flag = same_vec(vect1, vect2);
if(flag)
{
cout << "vect1 and vect2 is identical!"<<endl;
}
else
{
cout << "vect1 and vect2 is not identical!"<<endl;
}
return 0;
}
运行结果: