G
Gaijinco
I'm not quite sure why this code doesn't works:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
class word
{
string letters;
string sorted;
public:
word(string&s)
{
letters=s;
sort(s.begin(),s.end());
sorted=s;
}
friend bool lt(word& a, word& b)
{
return (a.sorted < b.sorted) < 0 ? true: false;
}
friend ostream& operator<<(ostream& out, vector<word>& v)
{
for(int i=0; i<v.size(); ++i)
cout << v.letters << endl;
return out;
}
};
int main()
{
vector<word>dict;
string aux;
cin >> aux;
while(aux!="#")
{
word w(aux);
dict.push_back(w);
cin >> aux;
}
sort(dict.begin(),dict.end(),lt);
cout << dict << endl;
return 0;
}
There's something wrong with the function "lt" but i'm not sure what.
In the prototype it says:
StrictWeakOrdering cmp but I'm not sure what does that mean, maybe
something about the kind of iterators I need to use?
Thanks!
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
class word
{
string letters;
string sorted;
public:
word(string&s)
{
letters=s;
sort(s.begin(),s.end());
sorted=s;
}
friend bool lt(word& a, word& b)
{
return (a.sorted < b.sorted) < 0 ? true: false;
}
friend ostream& operator<<(ostream& out, vector<word>& v)
{
for(int i=0; i<v.size(); ++i)
cout << v.letters << endl;
return out;
}
};
int main()
{
vector<word>dict;
string aux;
cin >> aux;
while(aux!="#")
{
word w(aux);
dict.push_back(w);
cin >> aux;
}
sort(dict.begin(),dict.end(),lt);
cout << dict << endl;
return 0;
}
There's something wrong with the function "lt" but i'm not sure what.
In the prototype it says:
StrictWeakOrdering cmp but I'm not sure what does that mean, maybe
something about the kind of iterators I need to use?
Thanks!