KarinaOfGSHS41stLSB's blog

By KarinaOfGSHS41stLSB, history, 5 months ago, In English

I see some very good coders such as snuke, Petr do this. struct Solver and writing their actual solution in the Solver's method void solve(). Is there any practical benefit of doing this?

  • Vote: I like it
  • +27
  • Vote: I do not like it

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

They probably get used to code in Java, hence they use OOP/struct in C++.

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Don't know about them but i personally use this so that in multiple tc's questions i can write

This

Instead of

This
  • »
    »
    5 months ago, # ^ |
    Rev. 2   Vote: I like it +3 Vote: I do not like it

    really convenient, no need to if -> break for all like 3 looped loops, just return -> ez gg

»
5 months ago, # |
  Vote: I like it +11 Vote: I do not like it

Ability to reset global variables at tasks with multitests

  • »
    »
    5 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    can't I just reset global variables just with void solve()? why need struct Solver?

    • »
      »
      »
      5 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      It's about convenience, not just ability. Having ctors and dtors do work for you is convenient.

    • »
      »
      »
      5 months ago, # ^ |
        Vote: I like it -10 Vote: I do not like it

      One might forget to clear some vector

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

One advantage is that order of function defintions doesn't matter. You can use a function defined below your main function inside main function.

Code Example