CHAPTER11-33.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER11-33.cpp
- #include <iostream>
- #include <numeric>
- #include <functional>
- #include <vector>
- #include <iterator>
- using namespace std;
- typedef vector < int > IntegerArray;
- typedef ostream_iterator < int, char, char_traits<char> > IntOstreamIt;
- void main ()
- {
- IntOstreamIt itOstream(cout," ");
- IntegerArray rgIA;
- rgIA.push_back(5661);
- rgIA.push_back(7456);
- rgIA.push_back(10995);
- rgIA.push_back(17019);
- rgIA.push_back(24394);
- rgIA.push_back(30376);
- rgIA.push_back(35758);
- copy(rgIA.begin(),rgIA.end(),itOstream);
- cout << endl;
- IntegerArray rgDifferences(7);
- IntegerArray::iterator itDifferences = rgDifferences.begin();
- adjacent_difference(rgIA.begin(),rgIA.end(),itDifferences);
- cout << "The adjacent differences are: ";
- copy(rgDifferences.begin()+1,rgDifferences.end(),itOstream);
- cout << endl;
- IntegerArray rgGT(6);
- IntegerArray::iterator itGT = rgGT.begin();
- adjacent_difference(rgDifferences.begin()+1,rgDifferences.end(),itGT,less<int>());
- cout << "Which adjacent distances are greater:" << endl
- << "(If you have [a,b,c], then you have [1,0] if a>b and b<=c)"<< endl;
- copy(rgGT.begin()+1,rgGT.end(),itOstream);
- cout << endl;
- }