#include <set>
#include <list>
#include <string>
#include <iostream>
using namespace std;
int main() {
// set prevents dupes, list preserves order
set<string> theset;
list<set<string>::iterator> thelist;
// insertion is like this:
auto insert = [&] (const string &str) {
auto inserted = theset.insert(str);
if (inserted.second)
thelist.push_back(inserted.first);
};
// then, for example:
insert("zebra"); // first zebra
insert("chair a"); // first chair a
insert("desk"); // first desk
insert("desk");
insert("chair b"); // first chair b
insert("chair a");
insert("chair a");
insert("table"); // first table
insert("chair a");
insert("xylophone"); // first xylophone
insert("zebra");
// access can be done like:
for (auto istr : thelist)
cout << *istr << endl;
}
I2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCgkvLyBzZXQgcHJldmVudHMgZHVwZXMsIGxpc3QgcHJlc2VydmVzIG9yZGVyCglzZXQ8c3RyaW5nPiB0aGVzZXQ7CglsaXN0PHNldDxzdHJpbmc+OjppdGVyYXRvcj4gdGhlbGlzdDsKCQoJLy8gaW5zZXJ0aW9uIGlzIGxpa2UgdGhpczoKCWF1dG8gaW5zZXJ0ID0gWyZdIChjb25zdCBzdHJpbmcgJnN0cikgewoJCWF1dG8gaW5zZXJ0ZWQgPSB0aGVzZXQuaW5zZXJ0KHN0cik7CgkJaWYgKGluc2VydGVkLnNlY29uZCkKCQkJdGhlbGlzdC5wdXNoX2JhY2soaW5zZXJ0ZWQuZmlyc3QpOwoJfTsKCgkvLyB0aGVuLCBmb3IgZXhhbXBsZToKCWluc2VydCgiemVicmEiKTsgICAgICAgLy8gZmlyc3QgemVicmEKCWluc2VydCgiY2hhaXIgYSIpOyAgICAgLy8gZmlyc3QgY2hhaXIgYQoJaW5zZXJ0KCJkZXNrIik7ICAgICAgICAvLyBmaXJzdCBkZXNrCglpbnNlcnQoImRlc2siKTsKCWluc2VydCgiY2hhaXIgYiIpOy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