#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
vector<string> textLines{"AAA", "AAA", "BBB", "CCC"};
int main()
{
sort(textLines.begin(), textLines.end());
vector<string> duplicates;
auto iter = unique(textLines.begin(), textLines.end(), [&duplicates](auto& first, auto& second) -> bool {
if (first == second)
{
duplicates.push_back(second);
return true;
}
return false;
});
textLines.resize(distance(textLines.begin(), iter));
std:: cout << "Filtered:" << std::endl;
for (auto& t : textLines)
{
std::cout << t << std::endl;
}
std:: cout << "Duplicates:" << std::endl;
for (auto& t : duplicates)
{
std::cout << t << std::endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdmVjdG9yPHN0cmluZz4gdGV4dExpbmVzeyJBQUEiLCAiQUFBIiwgIkJCQiIsICJDQ0MifTsKCmludCBtYWluKCkKewoJc29ydCh0ZXh0TGluZXMuYmVnaW4oKSwgdGV4dExpbmVzLmVuZCgpKTsKCQoJdmVjdG9yPHN0cmluZz4gZHVwbGljYXRlczsKCWF1dG8gaXRlciA9IHVuaXF1ZSh0ZXh0TGluZXMuYmVnaW4oKSwgdGV4dExpbmVzLmVuZCgpLCBbJmR1cGxpY2F0ZXNdKGF1dG8mIGZpcnN0LCBhdXRvJiBzZWNvbmQpIC0+IGJvb2wgewoJCWlmIChmaXJzdCA9PSBzZWNvbmQpCgkJewoJCQlkdXBsaWNhdGVzLnB1c2hfYmFjayhzZWNvbmQpOwoJCQlyZXR1cm4gdHJ1ZTsKCQl9CgkJCgkJcmV0dXJuIGZhbHNlOwoJfSk7Cgl0ZXh0TGluZXMucmVzaXplKGRpc3RhbmNlKHRleHRMaW5lcy5iZWdpbigpLCBpdGVyKSk7CgkKCXN0ZDo6IGNvdXQgPDwgIkZpbHRlcmVkOiIgPDwgc3RkOjplbmRsOwoJZ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