// данного слова fifndef NSTRI

Автор admin Вторник, 26 мая 2009 11:32

// данного слова fifndef NSTRING_H fdefine NSTRING_H #include #include #include #include #include typedef std::pair psi: // Сравнение только по первому элементу bool operator==(const psi& 1. const psi& r) { return 1.first =- r.first: } class NString { std::string s: int thisOccurrence; // Отслеживание количества вхождений: typedef std:;vector vp; typedef vp::iterator vpit; static vp words: void addString(const std::string& x) { psi p(x. 0): vpit it = std: :find(words.beginO. words.endO. p); if(it != words.endO) thisOccurrence = ++it->second; else { thisOccurrence = 0: words.push_back(p): } } public: NStringO : thisOccurrence(O) {} NStringCconst std::string& x) : s(x) { addString(x): } NStringCconst char* x) : s(x) { addString(x); } // Автоматически сгенерированные оператор = // и копирующий конструктор здесь подойдут. friend std: :o stream& operator«( std::ostream& os. const NStringS ns) { return os « ns.s « ” [" « ns.thisOccurrence « "]“: } // Оператор необходим для сортировки. Сравнение // производится только по строкам, без учет


Комментарии закрыты.