void pentagonal_num(vector<int> &vec, int pos);
void display(const vector<int> &vec);
inline bool is_size_ok(vector<int> &vec,int size);
void main()
{
vector<int> pent;
if (is_size_ok(pent,0))
display(pent);
if (is_size_ok(pent,6))
display(pent);
if (is_size_ok(pent,18))
display(pent);
if (is_size_ok(pent,72))
display(pent);
}
bool is_size_ok(vector<int> &vec, int size)
{
const int max_size=64;
if (size<=0||size>max_size)
{
cout<<"requested size is not supported:"<<size<<endl;
return false;
}
if (vec.size()<size)
pentagonal_num(vec, size);
return true;
}
void pentagonal_num(vector<int> &vec, int pos)
{
for (int ix=vec.size()+1; ix<=pos; ++ix)
{vec.push_back((ix * (3*ix-1))/2);}
}
void display(const vector<int> &vec)
{
for (int ix=0; ix<vec.size(); ++ix)
cout<<vec[ix]<<’ ’;
cout<<endl;
}
/////////////////////////////////////////////////////////
#pragma warning (disable:4786)
#include <iostream>
#include <vector>
#include <string>
using namespace std;
template <typename elemtype>
inline elemtype* beginme(vector<elemtype> &vec)
{
return vec.empty() ? 0 : &vec[0] ;
}
template <typename elemtype>
inline elemtype* endme(vector<elemtype> &vec)
{
return vec.empty() ? 0 : &vec[vec.size()] ;
}
template <typename elemtype>
elemtype *find( elemtype *first, elemtype *last, elemtype &value )
{
if( ! first || ! last )
return 0;
for( ; first != last; first++ )
if( *first == value )
return first;
return 0;
}