decoder__'s blog

By decoder__, history, 6 years ago, In English

I have seen in many people's code that they use a solve function instead of writing the logic in the main function. What advantage it has over writing the code directly in the main function?

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

| Write comment?
»
6 years ago, hide # |
 
Vote: I like it +72 Vote: I do not like it

You can use return directly in solve() in case there are test cases, while in int main() you can't

»
6 years ago, hide # |
 
Vote: I like it +17 Vote: I do not like it

I personally use it because you can easily end the function with return(end).

»
6 years ago, hide # |
 
Vote: I like it -26 Vote: I do not like it

I think it doesnt have obvious advantages. But many people are used to it since it looks comfortable. After all, the choice is up to you.

»
6 years ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

It's good to split everything in functions

»
6 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Isn't it too obvious? Asking everything sucks

»
6 years ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

What is there in it to downvote except colortag?

»
6 years ago, hide # |
 
Vote: I like it +20 Vote: I do not like it
solve()
main()

You decide.

»
6 years ago, hide # |
Rev. 2  
Vote: I like it +6 Vote: I do not like it

.....................................................................................