Could I again get some help in improving this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Could I again get some help in improving this code?

The 1st link shows how the code looked before. And I would like to thank Coder Kitten , Volodymyr Chelnokov and Nayeem Islam Shanto...শান্ত for helping me reach so far with this code. But now i have another problem, check out inside the 2nd link. Could I get some help guys? Once again? https://www.sololearn.com/discuss/2591536/?ref=app https://code.sololearn.com/c3R1T5hB5lqy/?ref=app

16th Nov 2020, 2:18 PM
Md Shahriar Rahman
Md Shahriar Rahman - avatar
2 Answers
+ 6
The size of the code is not relevant in regards to the execution time. I made a simpler program which requires less calculations, but this solution I am giving is probably not the one you were supposed to find to solve your homework. Note that the program works even with characters 😅 you can make some modification to allow only numbers. https://code.sololearn.com/cCVLzc0T6Vk2/?ref=app
16th Nov 2020, 2:57 PM
Davide
Davide - avatar
+ 5
The problem with getting the time limit is not that the code is too big, but that you have a while (i == 1000000) inner loop that never modifies i, so once you get inside you can never leave. Still the code being too large is a problem (first of all, because it hinders understanding the code) What i'd do: a) have a boolean flag saying if we have printed anything yet (initialized with false) b) inside the loop if flag is false, if a is nonzero, print it (with no extra zeroes) and set flag to true. If the flag is true, just printf(",%03d",a) -- %03d specifier says that the field must be 3 digits wide, with unused digits printed as zeroes - just what we need. Using flag variables is ugly, but here i don't know how to do better - maybe someone else advices a better way.
16th Nov 2020, 2:33 PM
Volodymyr Chelnokov
Volodymyr Chelnokov - avatar