习题9.20
来源:互联网 发布:软件许可协议文本 编辑:程序博客网 时间:2024/05/17 22:15
Exercise 9.20:
Write a program to compare whether a vector<int> contains the same elements as alist<int>.
编写程序判断一个 vector<int> 容器所包含的元素是否与一个 list<int> 容器的完全相同。
#include<iostream>#include<list>#include<vector>using namespace std;int main(){int vecValue, listValue;vector<int> my_vec;list<int> my_list;cout <<"input vector numbers, Ctrl+z to end" <<endl;while(cin >> vecValue){my_vec.push_back(vecValue);} cin.clear();//注意,此处要使流状态重置为有效cout<<"input list numbers, Ctrl+z to end" <<endl;while(cin >> listValue){my_list.push_back(listValue);}if(my_vec.size() != my_list.size()){cout <<"the result is different"<<endl;goto Pause;}else{vector<int> ::iterator viter = my_vec.begin();list<int> ::iterator liter = my_list.begin();while(viter != my_vec.end()){if(*viter != *liter){cout <<"the result is different"<<endl;break;}viter++;liter++;}if(viter == my_vec.end()){cout <<"the result is same"<<endl;}}Pause: system("pause");return 0;}
- 习题9.20
- 习题9.20
- c++primer 习题9.20
- 习题
- 习题
- 习题
- 习题
- 习题
- 习题
- 习题
- 习题
- 习题
- 习题
- 习题
- 习题
- 习题
- 习题
- 习题
- 忘记MySql的root密码的简单解决办法
- 排序算法解析——冒泡排序、选择排序、快速排序
- C#编码规范
- android:MediaPlayer
- 通过销售订单领用到成本中心,FI替代实现不同成本中心记账科目不同
- 习题9.20
- adb shell 删除文件
- IE9兼容性视图的设置
- android: 长按删除listview的item
- div中class与id的区别及应用
- Android asmack 简单功能的实现
- Unix toolbox注解1之Linux系统硬件信息
- Boardcast03
- C/C++程序员应聘常见面试题深入剖析