-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ feat: add ACODE - classical SPOJ #2
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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