标签:
转载:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=26354188&id=3198604
1 #include <iostream> 2 #include <vector> 3 4 using namespace std; 5 6 int main() 7 { 8 vector<int> ivec1, ivec2; 9 int ival,iva2; 10 11 cout<<"Enter numbers for vector1(-1 to end): "<<endl; 12 cin >> ival; 13 while (ival != -1) 14 { 15 ivec1.push_back(ival); 16 cin >> ival; 17 } 18 cout<<"Enter numbers for vector2(-1 to end): "<<endl; 19 cin >> ival; 20 while (ival != -1) 21 { 22 ivec2.push_back(ival); 23 cin >> iva2; 24 } 25 26 if (ivec1.size() != ivec2.size()) 27 cout<<"Vector1 is not equal to vector2."<<endl; 28 else if(ivec1.size() == 0) 29 cout<<"Vector1 is equal to vector2"<<endl; 30 else 31 { 32 vector<int>::iterator iter1, iter2; 33 iter1 = ivec1.begin(); 34 iter2 = ivec2.begin(); 35 while (iter1 != ivec1.end() && iter2 != ivec2.end() 36 && *iter1 == *iter2) 37 { 38 ++iter1; 39 ++iter2; 40 } 41 if(iter1 == ivec1.end()) 42 cout<<"Vector1 is equal to vector2."<<endl; 43 else 44 cout<<"Vector1 is not equal to vector2."<<endl; 45 } 46 return 0; 47 }
标签:
原文地址:http://www.cnblogs.com/chechen/p/4204279.html