Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

✨ feat: add ACODE - classical SPOJ #2

wants to merge 1 commit into from

Conversation

tusharnankani
Copy link

@tusharnankani tusharnankani commented Oct 5, 2020

Closes issue #1

Copy link
Member

@Abhijit2505 Abhijit2505 left a 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>
Copy link
Member

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];
Copy link
Member

@Abhijit2505 Abhijit2505 Oct 6, 2020

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];
Copy link
Member

@Abhijit2505 Abhijit2505 Oct 6, 2020

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 of a.
  • We can use better names for i & j.

int main() {
char a[5010];
int i, j;
scanf("%s", a);
Copy link
Member

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];
Copy link
Member

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;
Copy link
Member

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++ ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request SPOJ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Sphere Online Judge Classical Problem - ACODE
2 participants