Skip to content

Instantly share code, notes, and snippets.

@Dropa
Created November 16, 2017 19:14
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 Dropa/f63f0080453258cbc07a7d6df3e4a63b to your computer and use it in GitHub Desktop.
Save Dropa/f63f0080453258cbc07a7d6df3e4a63b to your computer and use it in GitHub Desktop.
#include <iostream>
#include <set>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
using std::set;
using std::string;
using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::istream_iterator;
using std::back_inserter;
using std::less;
bool insert_new(const char& c);
int main() {
cout << "Insert characters, end with CTRL+Z (+ enter)" << endl;
vector<char> c, v;
copy_if(istream_iterator<char>(cin),
istream_iterator<char>(),
back_inserter(c),
[](const char c) {
return insert_new(c) == true;
});
sort(c.begin(), c.end(), less<char>());
for (auto i : c) {
cout << i;;
}
getchar();
return 0;
}
bool insert_new(const char& c) {
static set<char> cc;
return cc.insert(c).second;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment