Skip to content

Instantly share code, notes, and snippets.

/P5P5

Created October 25, 2012 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3949970 to your computer and use it in GitHub Desktop.
Save anonymous/3949970 to your computer and use it in GitHub Desktop.
{ // Open scope block for part 6
cout << "\n\nStarting part 6 ...\n\n";
cout << "Input the minimum and maximum random int: ";
int minRange, maxRange;
cin >> minRange >> maxRange;
cout << "Input the length of the vector: ";
int vectorLength;
cin >> vectorLength;
vector<int> hasRepeats(vectorLength);
cout << " Vector beforehand: \t";
for (int i = 0; i < vectorLength; i = i + 1)
{ hasRepeats[i] = minRange + rand()%(maxRange - minRange + 1);
cout << hasRepeats[i] << " ";
}
cout << "\n";
////////////////////////////////////////////
// Your code for part 6 gets patched in here
// take out all multiples
//check if v[i] is equal to previous ones
//IF DUPLICATE, set to maxRange + 1 and then pop_back number of duplicates
int counter = 0;
for(int i = 0; i < vectorLength; i++)
{
for(int j = 0; j <= vectorLength ;j++)
{
if(hasRepeats[i] == hasRepeats[j])
{
hasRepeats[i] = maxRange + 1;
counter = counter + 1;
}
if(counter > 0)
{
for(int k = 0; k < counter; k++)
{
hasRepeats.pop_back();
}
}
}
}
////////////////////////////////////////////
cout << " Vector afterhand: \t";
for (int i = 0; i < hasRepeats.size(); i = i + 1)
{ cout << hasRepeats[i] << " ";
}
cout << "\n";
} // close the scope block for part 6
//////////////////////////////// End of Program ////////////////////////////////
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment