-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main() { | ||
char a[5010]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using Using There was a problem hiding this comment. Choose a reason for hiding this commentThe 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,
|
||
int i, j; | ||
scanf("%s", a); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well as I have mentioned above, although We are using C++ and let's use it's total feature. I would like you to explore, |
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. instead of using I would like you to explore Also, can you make the code generic by using some Templates? |
||
for(i = 0; i < n; i++) | ||
b[i] = 0; | ||
b[0] = 1; | ||
for(i = 1; i < n; i++) | ||
{ | ||
j = (a[i - 1] - '0') * 10 + (a[i] - '0'); | ||
if(a[i] - '0') | ||
b[i] = b[i - 1]; | ||
if(j > 9 && j < 27) | ||
{ | ||
if(i == 1) | ||
b[i] = b[i] + 1; | ||
else | ||
b[i] = b[i] + b[i-2]; | ||
} | ||
} | ||
printf("%lld\n", b[n - 1]); | ||
scanf("%s", a); | ||
} | ||
if(a[0] == '0') | ||
return 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. What about approaching the problem through the OOP functionalities of C++ ? |
||
} |
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 byGCC
compiler only. As our repository is a learner-friendly repo, I would like you to include all the libraries/header files used.