✨ feat: add ACODE - classical SPOJ#2
✨ feat: add ACODE - classical SPOJ#2tusharnankani wants to merge 1 commit intoDSCGGV:masterfrom tusharnankani:SPOJ-1
Conversation
Abhijit2505
left a comment
There was a problem hiding this comment.
As this is a Learner's Repository, we follow some code standards. I would like you to work upon the following issues and let me know in case of any queries.
Get started with it.
| @@ -0,0 +1,33 @@ | |||
| #include <bits/stdc++.h> | |||
There was a problem hiding this comment.
Although <bits/stdc++.h> is almost perfect for Cp, but still it is supported by GCC compiler only. As our repository is a learner-friendly repo, I would like you to include all the libraries/header files used.
| using namespace std; | ||
|
|
||
| int main() { | ||
| char a[5010]; |
There was a problem hiding this comment.
Using char is a good but from 'C++' point of view, it will be better if we use the features of the language to a larger extent.
Like we have a string class inside CPP, and that can be used instead of char.
Using char is not wrong, but it is not a good practise as we are using 'modern C++'. Let's utilize the language properly.
| using namespace std; | ||
|
|
||
| int main() { | ||
| char a[5010]; |
There was a problem hiding this comment.
Writing clean code is a great part of programming, not for CP contests, but for other human beings to understand your code.
Some points to be kept in mind,
- Use proper variable names, like we can use
array[]instead ofa. - We can use better names for
i&j.
| int main() { | ||
| char a[5010]; | ||
| int i, j; | ||
| scanf("%s", a); |
There was a problem hiding this comment.
Well as I have mentioned above, although scanf and printf are faster than the contemporary cin and cout, but I encourage you to use the later.
We are using C++ and let's use it's total feature. scanf and printf are also included in C programming language. Let's do something different in CPP.
I would like you to explore, getline(cin,str) function a little deeper.
| while(a[0] != '0') | ||
| { | ||
| int n = strlen(a); | ||
| long long int b[n]; |
There was a problem hiding this comment.
instead of using long long int frequently in a bigger code, we can just use the powerful C++ feature.
I would like you to explore typedef and #define functionality of C++.
Also, can you make the code generic by using some Templates?
Hint : Use template<class T>
| scanf("%s", a); | ||
| } | ||
| if(a[0] == '0') | ||
| return 0; |
There was a problem hiding this comment.
What about making the code modular? That will be easier for the learners to understand the I/O as well as the main algo.
Instead of including all the code inside the main function (which is a pretty bad standard in the industry), you may try to form some functions!
What about approaching the problem through the OOP functionalities of C++ ?
Closes issue #1