Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

Interesting C++ problem

Revision en1, by BekzhanKassenov, 2016-11-23 04:01:35

Hello CodeForces community!

Recently I've recalled one interesting C++ problem. In short: is it possible to write functions action and cond in such a way, so that the following code snippets work differently:

// Snippet #1:
action();
while (cond()) {
    action();
}
// Snippet #2:
do {
    action();
} while (cond());

More formally: suppose you're given the following three files:

common.h
main_while.cpp
main_do_while.cpp

You're only allowed to modify common.h. You have to do that in such a way, so that Action word is printed different amount of times by execution of main_while.cpp and main_do_while.cpp.

One of the possible solutions (try to think yourself before opening the spoiler!):

Dirty hack

Share your solutions in the comments and don't forget to hide them under the spoilers! It would be interesting to see something smarter (e.g. solution which will work in any language with analogues of while and do-while)

Tags c++, interesting problems, dirty hack

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
ru2 Russian BekzhanKassenov 2016-11-23 04:07:36 69 (опубликовано)
en1 English BekzhanKassenov 2016-11-23 04:01:35 1901 Initial revision for English translation
ru1 Russian BekzhanKassenov 2016-11-23 03:50:05 1829 Первая редакция (сохранено в черновиках)