Debian Codegraph @

yo/containers/examples/prioritywords2.cc

raw
1 #include <iostream>
2 #include <string>
3 #include <queue>
4
5 class Text
6 {
7 std::string d_s;
8
9 public:
10 Text(std::string const &str)
11 :
12 d_s(str)
13 {}
14 operator std::string const &() const
15 {
16 return d_s;
17 }
18 bool operator<(Text const &right) const
19 {
20 return d_s > right.d_s;
21 }
22 };
23
24 using namespace std;
25
26 int main()
27 {
28 priority_queue<Text> q;
29 string word;
30
31 while (cin >> word)
32 q.push(word);
33
34 while (q.size())
35 {
36 word = q.top();
37 cout << word << '\n';
38 q.pop();
39 }
40 }