I would refrain from including
<bits/stdc++.h>. This includes pretty much every single STL header which is certainly easier to use but in general you should only include what you actually need. It's also not a standard C++ header file and hence not portable.using namespace stdis generally considered bad practiceconsidered bad practice.Instead of using
#defineyou should usetypedef(more herehere).Use spaces to declutter your code, i.e. instead of
for(int i=0;i<s.length();i++)it should befor (int i = 0; i < s.length(); i++). This increases readability.Indent your code properly and consistently. Again this improves readability. This is especially important when you decide to omit braces for single line statements in
forloops orifblocks like you did here:
I would refrain from including
<bits/stdc++.h>. This includes pretty much every single STL header which is certainly easier to use but in general you should only include what you actually need. It's also not a standard C++ header file and hence not portable.using namespace stdis generally considered bad practice.Instead of using
#defineyou should usetypedef(more here).Use spaces to declutter your code, i.e. instead of
for(int i=0;i<s.length();i++)it should befor (int i = 0; i < s.length(); i++). This increases readability.Indent your code properly and consistently. Again this improves readability. This is especially important when you decide to omit braces for single line statements in
forloops orifblocks like you did here:
I would refrain from including
<bits/stdc++.h>. This includes pretty much every single STL header which is certainly easier to use but in general you should only include what you actually need. It's also not a standard C++ header file and hence not portable.using namespace stdis generally considered bad practice.Instead of using
#defineyou should usetypedef(more here).Use spaces to declutter your code, i.e. instead of
for(int i=0;i<s.length();i++)it should befor (int i = 0; i < s.length(); i++). This increases readability.Indent your code properly and consistently. Again this improves readability. This is especially important when you decide to omit braces for single line statements in
forloops orifblocks like you did here:
I would refrain from including
<bits/stdc++.h>. This includes pretty much every single STL header which is certainly easier to use but in general you should only include what you actually need. It's also not a standard C++ header file and hence not portable.using namespace stdis generally considered bad practice.Instead of using
#defineyou should usetypedef(more here).Use spaces to declutter your code, i.e. instead of
for(int i=0;i<s.length();i++)it should befor (int i = 0; i < s.length(); i++). This increases readability.Indent your code properly and consistently. Again this improves readability. This is especially important when you decide to omit braces for single line statements in
forloops orifblocks like you did here:
for(int j=i;j<13+i;j++)
prod*=(s[j]-'0'); if(prod>=max) max=prod; This should at least be:
for (int j = i; j < 13 + i; j++) prod *= (s[j] - '0'); if (prod >= max) max = prod; to make clear what belongs into which block. Better would be:
for (int j = i; j < 13 + i; j++) { prod *= (s[j] - '0'); } if (prod >= max) { max = prod; } Short code is not necessarily good code because it tends to obfuscate the meaning and is more prone to contain bugs.
Cleaned up the code looks like this:
#include <string> typedef unsigned long long ull int main() { string s; std::getline(cin, s); ull max = 0; for (int i = 0; i < s.length(); i++) { ull prod = 1; for (int j = i; j < 13 + i; j++) { prod *= (s[j] - '0'); } if (prod >= max) { max = prod; } } std::cout << max; return 0; }