# Include <list> # include <vector> # include <string> # include <algorithm> # include <iterator> # include <iostream> using namespace std; bool isShorter (const string & s1, const string & s2) {return s1.size () <s2.size ();} bool GT6 (const string & s) {return s. size ()> = 6;} string make_plural (size_t ctr, const string & word, const string & ending) {return (ctr = 1 )? Word: word + ending; // make_plural (wc, "word", "s") when the number of words in the input Chinese text is greater than one, s is added after word, it is the plural word of words !} Int main () {// words: the quick red fox jumps over the slow red turtlevector <string> words; vector <string >:: iterator noUnique; // Add words to vectorwords. push_back (string ("the"); words. push_back (string ("quick"); words. push_back (string ("red"); words. push_back (string ("fox"); words. push_back (string ("jumps"); words. push_back (string ("over"); words. push_back (string ("the"); words. push_back (string ("slow"); words. push _ Back (string ("red"); words. push_back (string ("turtle"); // cout <"before sort:" <endl; cout <"------------------------" <endl; for (vector <string >:: iterator iter = words. begin (); iter! = Words. end (); ++ iter) {cout <* iter <endl;} cout <"----------------------------" <endl; // sort and then output sort (words. begin (), words. end (); cout <"after sort:" <endl; cout <"--------------------------" <endl; for (iter = words. begin (); iter! = Words. end (); ++ iter) {cout <* iter <endl;} cout <"----------------------------" <endl; // remove duplicates, then output noUnique = unique (words. begin (), words. end (); // copy non-repeating elements to the front end of the sequence, and the returned iterator points to the words at the next location beyond the end of the non-repeating element range. erase (noUnique, words. end (); // remove duplicate elements cout <"after unique:" <endl; cout <"----------------------------" <endl; for (iter = words. begin (); iter! = Words. end (); ++ iter) {cout <* iter <endl;} cout <"----------------------------" <endl; // sort by the number of characters, find the number of elements with a length greater than 6 and output stable_sort (words. begin (), words. end (), isShorter); vector <string >:: size_type wc = count_if (words. begin (), words. end (), GT6); cout <wc <"<make_plural (wc," word "," s ") <"6 characters or longer" <endl; for (iter = words. begin (); iter! = Words. end (); ++ iter) {if (GT6 (* iter) {cout <* iter <endl ;}} cout <"------------------------" <endl; return 0 ;}