码迷,mamicode.com
首页 > 其他好文 > 详细

判断两个vector是否相等

时间:2015-01-05 20:09:08      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:

转载: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 }

 

判断两个vector是否相等

标签:

原文地址:http://www.cnblogs.com/chechen/p/4204279.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!