/* kalle är dum kalle kalle super kalle super super super kalle super super super kalle hej på dig hej hej super hej hej super hej hej hej super hej hej */ #include #include #include #include #include #include #include using namespace std; random_device rd{}; mt19937 mtrd{ rd() }; template int last(T const& v) { return static_cast(v.size()) - 1; } class Personality { public: virtual ~Personality() = default; virtual void process(vector& whisper) const = 0; }; class Forgetful : public Personality { public: // forgets N random words Forgetful(int n) : n{n} {} virtual void process(vector& whisper) const override { for ( int i{}; i < n; ++i ) { uniform_int_distribution d{0, last(whisper) }; whisper.erase( begin(whisper) + d(mtrd) ); } } private: int n; }; class Absent_Minded : public Personality { public: // duplicates N random words and insert at random position Absent_Minded(int n) : n{n} {} virtual void process(vector& whisper) const override { for ( int i{}; i < n; ++i ) { uniform_int_distribution d{0, last(whisper)}; whisper.insert( begin(whisper) + d(mtrd), whisper.at(d(mtrd)) ); } } private: int n; }; class Confused : public Personality { public: // swaps N random words Confused(int n) : n{n} {} virtual void process(vector& whisper) const override { for ( int i{}; i < n; ++i ) { uniform_int_distribution d{0, last(whisper)}; swap( whisper.at(d(mtrd)), whisper.at(d(mtrd)) ); } } private: int n; }; class Confabulator : public Personality { public: // inserts "super" before the longest word virtual void process(vector& whisper) const override { whisper.insert( max_element(begin(whisper), end(whisper), [](string const& a, string const& b){ return a.length() < b.length(); }), "super"); } }; int main() { vector> v; v.push_back( make_unique(2) ); v.push_back( make_unique(2) ); v.push_back( make_unique() ); v.push_back( make_unique(2) ); string line; getline(cin, line); vector whisper; istringstream iss{line}; copy( istream_iterator{ iss }, istream_iterator{}, back_inserter(whisper) ); for ( auto const& p : v ) { p->process(whisper); copy( begin(whisper), end(whisper), ostream_iterator{cout, " "} ); cout << endl; } copy( begin(whisper), end(whisper), ostream_iterator{cout, " "} ); cout << endl; return 0; }