I am entering a programming competition in few weeks and have been tackling past papers. One question I am stuck on is to call a recursive function which computes all possible binary integers with n digits, eg user inputs 2, program prints out 00, 01, 10, 11. What is the best way to tackle this? How is it done?
Also, it's an ACM competition - are there any must study books for these competitions? Anything I should definitely read? It is in one months! I am really nervous and don't want to let my team down.
A solution in Java:
for(int i = 0; i < 1 << n; i++)
{
System.out.println(Integer.toBinaryString(i));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With