/*****************************************************************************
 * This is an illustration of vector erasure. When used with a top value of
 * 100,000 and a divisor of 2, there is a marked pause while the computer  
 * erases half the values in the starting vector.
 * ****************************************************************************/
#include <iostream>
#include<cctype>
#include <vector>
#include<string>
using std::cin; using std::cout;            
using std::endl;  using std::string;          
using std::vector;


void show_vector(const vector<int> & v);
int main()
{
	
	vector<int> V, div;
	int num, top;
	cout<<"Please enter the top positive integer under consideration: ";
	cin>>top;
	for(int i=1; i!=top+1; i++)
		V.push_back(i);//Load the vector with values 1-top

	cout<<"\nEnter an integer. The program will partition the values "
	       <<"into values\nthat integer divides evenly and "
      	       <<"values it does not.\nYour integer :";
	cin>>num;
vector<int>::iterator iter=V.begin();//This cannot be a const iterator
					     // because we plan to use it to 
					     // modify  V.
	while(iter!=V.end())
	{
		if(*iter%num==0)
		{
			div.push_back(*iter);//Push the value into the divisor
					    //vector.
			iter=V.erase(iter);//Erase it from the original. The
				           //erase function returns an iterator
					   //indicating the next value. 
					     
		}
		else
			++iter;
	}
	string ans;
	cout<<endl<<"Would you like a report? (y or n): ";
	cin>>ans;
	if(tolower(ans[0])=='y')
	{
	cout<<"\nMultiples of "<<num<<" are\n";
	show_vector(div);
	cout<<endl<<"\nNon-multiples of "<<num<<" are\n";
	show_vector(V);
	}
	return 0;
			
}
void show_vector(const vector<int>& v)
{
	for(vector<int>::const_iterator iter=v.begin(); iter!=v.end();++iter)
		cout<<*iter<<" ";
	/* We need a const iterator here because we passed v by constant 
	 * reference.
	 */   
	return;
}
	
