1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <map>
#include <iterator>
#include <algorithm>
std::map<std::string,int> histgram;
void record(const std::string &s){
histgram[s]++;
}
void print(const std::pair<std::string,int> &r){
std::cout<<"The string \""<<r.first<<"\" dispalyed "<<r.second<<" times!\n";
}
int _tmain(int argc, _TCHAR* argv[])
{
std::string from,to;
std::cin >> from >>to;
std::ifstream is(from.c_str());
std::istream_iterator <std::string> ii(is);
std::istream_iterator<std::string> eos;
std::vector<std::string> b(ii,eos);
std::sort(b.begin(),b.end());
std::cout<<"The length of b is :"<<b.size()<<"\n";
std::ofstream os(to.c_str());
std::ostream_iterator<std::string> oo(os,"\n");
std::unique_copy(b.begin(),b.end(),oo);
std::cout << "from is :"<<from<<", and to is: "<<to<<"\n";
std::vector<std::string>::const_iterator i=b.begin();
int n=0;
while(i !=b.end()){
++n;
std::cout << *i<<"\t";
i++;}
std::cout<<"\ntotal strings is: "<<n;
for_each(b.begin(),b.end(),record);
for_each(histgram.begin(),histgram.end(),print);
return !is.eof() || !os;
}
| |