Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Practice for programming competition

Tags:

java

recursion

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.

like image 739
Paul O'Connor Avatar asked Feb 03 '23 20:02

Paul O'Connor


1 Answers

A solution in Java:

for(int i = 0; i < 1 << n; i++)
  {
  System.out.println(Integer.toBinaryString(i));
  }
like image 59
fredley Avatar answered Feb 05 '23 08:02

fredley