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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| #include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::iterator;
bool equal(string s1, string s2) {
if ( s1.length() != s2.length())
return false;
for( unsigned int i = 0; i < s1.length(); i++){
if(tolower(s1[i]) != tolower(s2[i]))
return false;
}
return true;
}
bool before(string s1, string s2) {
int t;
bool test = false;
if (equal(s1, s2))
t = true;
else{
if ( s1.length() <= s2.length())
t = s1.length();
else
t = s2.length();
for(int i = 0; i < t; i++){
if(tolower(s1[i]) <= tolower(s2[i]))
test = true;
if(tolower(s1[i]) > tolower(s2[i]))
break;
}
}
return test;
}
void displayLine(string const& s) {
cout << s << endl;
}
int main(int argc, char const * argv[])
{
vector<string> V;
for( int i = 1; i < argc; i++)
V.push_back(argv[i]);
sort(V.begin(), V.end(), before);
vector<string>::iterator new_end = unique(V.begin(), V.end(), equal);
for_each(V.begin(), new_end, displayLine);
} |