89、90、91

#include <iostream>
#include <string>
#include <map>
using namespace std;
int main() {
 string str;
 map<string, int> ismap;
 int i = 0;
 while (1) {
  cout << "输入字符串: ";
  cin >> str;
  if (str == "QUIT")
   break;
  int counter = ismap.count(str);
  if (counter > 0)
   cout << str << "在映射中曾经出现过" << counter << "次" << endl;
  else
   cout << str << "在映射中没有出现过" << endl;
  ismap.insert(map<string, int>::value_type(str, i));
  i ++;
 }
 return 0;
}
#include <algorithm>
#include <iterator>
#include <vector>
#include <iostream>
#include <boost/array.hpp>
using namespace std;
//将来自输入迭代器p的n个T类型的数值排序,将结果通过输出迭代器result输出
template<class T, class InputIterator, class OutputIterator>
void mySort(InputIterator first, InputIterator last, OutputIterator result) {
 //通过输入迭代器p将输入数据存入向量容器s中
 vector<T> s;
 for (; first != last; ++first)
  s.push_back(*first);
 //对s进行排序,sort函数的参数必须是随机访问迭代器
 sort(s.begin(), s.end());
 //将s序列通过输出迭代器输出
 copy(s.begin(), s.end(), result);
}
int main() {
 //将s数组的内容排序后输出
 boost::array<double, 5> a = { 1.2, 2.4, 0.8, 3.3, 3.2 };
 mySort<double> (a.begin(), a.end(), ostream_iterator<double> (cout, " "));
 cout << endl;
 //从标准输入读入若干个整数,将排序后的结果输出
 mySort<int> (istream_iterator<int> (cin), istream_iterator<int> (),
   ostream_iterator<int> (cout, " "));
 cout << endl;
 return 0;
}
#include <functional>
#include <iostream>
#include <vector>
#include <algorithm>
#include <boost/bind.hpp>
using namespace std;
int main() {
 int intArr[] = { 30, 90, 10, 40, 70, 50, 20, 80 };
 const int N = sizeof(intArr) / sizeof(int);
 vector<int> a(intArr, intArr + N);
 vector<int>::iterator p = find_if(a.begin(), a.end(), bind(greater<int>(), _1, 40));
 if (p == a.end())
  cout << "no element greater than 40" << endl;
 else
  cout << "first element greater than 40 is: " << *p << endl;
 return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值