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?
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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?
Название |
---|
You can use return directly in solve() in case there are test cases, while in int main() you can't
"continue" keyword is also there.
but you have to use many breaks statements too if you want to end the current test case from a loop
i just use goto statement to go back to the starting of the test case loop, is that less efficient?
Actually you can use
goto
but that would make spaghetti codeI personally use it because you can easily end the function with return(end).
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.
https://discuss.codechef.com/t/why-solve/54680/13
It's good to split everything in functions
.
.
She probably changed her name as a joke. Danil is a famous Youtuber, well known for his staring contest videos (Google him if you don’t believe me). Definitely not her.
.
.
I've googled but found nothing, can you provide the link?
Isn't it too obvious? Asking everything sucks
What is there in it to downvote except colortag?
Exactly
But u know people will downvote this too...
I know
I think because this is a common question so people should first google search before asking in blogs.
You decide.
And I decide that trump is a good president.
.....................................................................................
.