1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
#include <locale>
#include <vector>
#include <algorithm>
#include <string>
bool caseCompare (std::string& lhs, std::string& rhs)
{
std::locale loc;
std::string left{}, right{};
for (size_t i = 0; i < lhs.size(); i++)
{
left += tolower(lhs[i], loc);
}
for (size_t i = 0; i < rhs.size(); i++)
{
right += tolower(rhs[i], loc);
}
lhs = left;
rhs = right;
return lhs < rhs;
}
int main()
{
std::vector <std::string> vec { "john", "John", "Mary", "james", "Charles", "chaRles", "Julia"};
std::sort(vec.begin(), vec.end(), caseCompare);
vec.erase(std::remove_if(vec.begin(), vec.end(), [&](const std::string x)
{return (std::count(vec.begin(), vec.end(), x) > 1);}), vec.end());
for (auto& elem : vec)
{
std::cout << elem << " ";
}
}
|