Saturday, 18 January 2014

Big integer in C++

I am not a big fan of code ppl write in coding competitions as it looks ugly. Too much is compromised for efficiency. One case in point is using big integer in C++. Some of the problems expect the use of big integer class. As there is no standard big integer in C++, one is left with 2 options. Write your own or copy somebody elses. But as one is allowed to submit only one file, it means everything will be dumped in that single file. I have decided to write my own when need arises. Only including the functions that I need.

Basically, a short way, at least for these competitions is to take every integer as a vector of intgeres (representing digits) and then do the operations as one did in school. Create the result digit by digit. Define operators for comparison on vector<int>. 

No comments:

Post a Comment