Last active
August 29, 2015 14:18
-
-
Save Dominent/5975f6f97cf8097aa9c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Input | |
You will be given many unsigned integers. | |
Output: | |
Find the repeats and remove them.Then display the numbers again. | |
*/ | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
bool VectorCheck(int value, vector <int> MyVector); | |
void inline DoNotClose(); | |
int main(){ | |
vector <int> values; | |
int input = 0; | |
bool Test = 0; | |
cout << "Enter numbers!, Press '-1' to stop\n"; | |
for (int i = -1;input != -1; ++i){ | |
cin >> input; | |
Test = VectorCheck(input, values); // Checking for equal values in vector. | |
if (i = 0) values.push_back(input); | |
else if (Test == false) values.push_back(input); | |
} // End of for() loop | |
sort(values.begin(), values.end()); // Sorting vector values. | |
cout << '\n'; | |
for (int x = 0; x < values.size(); ++x){ // printing out vector values. | |
cout << values[x] << '\t'; | |
} | |
DoNotClose(); | |
return 0; | |
} // End of main function. | |
bool VectorCheck(int value, vector <int> MyVector){ | |
bool flag; | |
vector<int>::const_iterator iter; | |
iter = find(MyVector.begin(), MyVector.end(), value); | |
if (iter != MyVector.end()) flag = 1; // Equal value detected. | |
else flag = 0; | |
return flag; | |
} | |
void inline DoNotClose(){ | |
char ch; | |
cin >> ch; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment