14.34
来源:互联网 发布:大连民族大学网络教学 编辑:程序博客网 时间:2024/05/22 10:38
//编写类似于gt_cls的类,//但测试两个值是否相等。使用该对象和标准库算法编写程序,替换序列中给定的所有实例
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tchar.h>
using namespace std;
class gt_cls
{
public:
gt_cls(int ival=0):val(ival){}
bool operator()(const int & iv)
{
return(iv == val);
}
private:
int val;
};
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "intput some nums(ctrl + z to end):" << std::endl;
vector<int>ivec;
int ival;
while (std::cin >> ival)
{
ivec.push_back(ival);
}//end of input the ivec
cin.clear();
cout << "input a num which will be replaced:\t";
int rp;
cin >> rp;
cout << "input a given num to insert:\t";
int givennum;
cin >> givennum;
//replace
replace_if(ivec.begin(), ivec.end(), gt_cls(rp), givennum);
cout << "now,the new vector<int>ivec,is:\n\t";
for (vector<int>::iterator it = ivec.begin(); it != ivec.end(); ++it)
{
cout << *it << "";
}
system("pause");
return 0;
}
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tchar.h>
using namespace std;
class gt_cls
{
public:
gt_cls(int ival=0):val(ival){}
bool operator()(const int & iv)
{
return(iv == val);
}
private:
int val;
};
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "intput some nums(ctrl + z to end):" << std::endl;
vector<int>ivec;
int ival;
while (std::cin >> ival)
{
ivec.push_back(ival);
}//end of input the ivec
cin.clear();
cout << "input a num which will be replaced:\t";
int rp;
cin >> rp;
cout << "input a given num to insert:\t";
int givennum;
cin >> givennum;
//replace
replace_if(ivec.begin(), ivec.end(), gt_cls(rp), givennum);
cout << "now,the new vector<int>ivec,is:\n\t";
for (vector<int>::iterator it = ivec.begin(); it != ivec.end(); ++it)
{
cout << *it << "";
}
system("pause");
return 0;
}
阅读全文
0 0
- 14.34
- 横跨科技时尚界便利贴相机 foream再发时尚线新品
- 脑洞大开 90后卖飞机的小女孩又众筹帆船
- 【国内首家VR虚拟现实主题公园】免费预约体验!
- 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 DP + 线段树 / SPFA
- 输出满足1+2+3...+n<8888的最大正整数.(作业)
- 14.34
- 扫雷
- Linux之shell基础
- 进程间的通讯方式_信号量
- mac 安装docker
- 国考将至 手机管家提醒:“包过关”你别信
- IP虽好仍需孵化平台助力 QQ浏览器提速优质内容接入
- codevs1160-蛇形矩阵(螺旋矩阵)
- 够快才畅快vivo X6跨界首发全球最强Hi-Fi芯片 或同时发布耳机