c++ – Olympiad problem with increased complexity

Question:

Salute to all dummies and gurus, developers and freelancers, programmers and coders! But this is not about the classification and hierarchy of our brother. It's about an Olympiad problem that I haven't been able to solve for a week. I know for sure: the solution is something simple and ingenious – but under what stone did it hide? So, harsh hashcode users, I ask for your help in solving this problem!

Task: Programming language: C ++. The program should have 1 single function for outputting information that can only write, i.e. cannot delete text, but only insert new one. Moreover, it works in the following way

Executable code:

func( "1" );

Conclusion:

(1)
[1]

Executable code:

func( "1" );
func( "2" );

Conclusion

(1)
(2)
[2]
[1]

Executable code:

func( "1" );
func( "2" );
func( "qwer" );

Conclusion

(1)
(2)
(qwer)
[qwer]
[2]
[1]

I'm sure the task is easy to solve, but I have no other option but to buffer the tail, change it, and replace the old tail with a new one. But then you have to use the removal of characters.

PS The problem is not entirely Olympiad, this problem was long ago in some powerful article on alternative programming where several examples were considered, but I don’t remember the implementation code for such a problem. And I can't find that article either. I can't write without deleting characters myself.

Answer:

Executable code:

func ("1"); func ("2"); func ("qwer");

Conclusion

(1) (2) (qwer) [qwer] [2] [1]


that is, you need to print in the normal and reverse order ????

as I understand it, you can only call the same function … (if yes, then the solution is below)

  1. make a func class and store std :: vector <std::string>
  2. make the func (string) constructor with recording the take in a vector and displaying it on the screen
  3. in the destructor, output the vector in reverse order

UPD :: well, it will still be "nice" to overload "operator ()" so as not to spoil the constructors

Scroll to Top