Bigint
Moderator: Board moderators
Bigint
Can you give me an URL refering a bigint class?
I've found some, but I didn't like they:
One is cannot print the value in decimal format, the other is complicated about how many digit is the maximum, and very slow, if I set much digits, however I only use small integers, etc.
I need something like this:
bigint b;
b=1e12; b*=b; b*=b; b++;
b.print();
b%=3;
b.print();
Can you help me?
I've found some, but I didn't like they:
One is cannot print the value in decimal format, the other is complicated about how many digit is the maximum, and very slow, if I set much digits, however I only use small integers, etc.
I need something like this:
bigint b;
b=1e12; b*=b; b*=b; b++;
b.print();
b%=3;
b.print();
Can you help me?
-
- A great helper
- Posts: 284
- Joined: Thu Feb 28, 2002 2:00 am
- Location: Germany
- Contact:
That is indeed possible with C++, and you can even write "cout << b". I haven't finished mine yet, but it's a very good task to learn about C++, I suggest you do it yourself.
Stroustrap has an example of a string class in his book as an example on how to use the copy constructor and the assignment operator. He has objects that represent the character array of a string and has a counter of the number of references to it.
I've also started writing a Permutation class with this very same technique, it's well worth learning this stuff.
Stroustrap has an example of a string class in his book as an example on how to use the copy constructor and the assignment operator. He has objects that represent the character array of a string and has a counter of the number of references to it.
I've also started writing a Permutation class with this very same technique, it's well worth learning this stuff.
The way you make your constructor (especially the copy) can greatly influence the overall efficiency of your class. Most of the design elements are not C++ specific. A strong understanding of OOP design should be sufficient.
For a decent implementation, look at one of the AP(advanced placement) Computer Science case studies from years back that implements a bigint class. That should give you some insight into making your own.
For a decent implementation, look at one of the AP(advanced placement) Computer Science case studies from years back that implements a bigint class. That should give you some insight into making your own.
-
- New poster
- Posts: 35
- Joined: Sat Jan 05, 2002 2:00 am
- Contact:
Wellcome to 288th problemStefan Pochmann wrote:That is indeed possible with C++, and you can even write "cout << b". I haven't finished mine yet, but it's a very good task to learn about C++, I suggest you do it yourself.
Stroustrap has an example of a string class in his book as an example on how to use the copy constructor and the assignment operator. He has objects that represent the character array of a string and has a counter of the number of references to it.
I've also started writing a Permutation class with this very same technique, it's well worth learning this stuff.
-
- A great helper
- Posts: 284
- Joined: Thu Feb 28, 2002 2:00 am
- Location: Germany
- Contact:
classes...
I uses struct instead but without any functions.
Yes I agree that classes make your code cleaner. Use them whenever you need to.
Yes I agree that classes make your code cleaner. Use them whenever you need to.
-
- A great helper
- Posts: 284
- Joined: Thu Feb 28, 2002 2:00 am
- Location: Germany
- Contact:
-
- Experienced poster
- Posts: 202
- Joined: Fri Mar 22, 2002 2:00 am
- Location: Chittagong. CSE - CUET
- Contact:
Isn't class variables and functions share more memory than simple string processing with pointers? I think for contests (real time + online) if string processing used with pointers that will be more fast and take less memory. But dangling pointers can crash the program or make RTE !
We are all in a circular way, no advances, only moving and moving!
The way I've always looked at it, classes *can* make just as good and fast and easy code as without, but it's really easy to screw it up and end up with slow code. I use classes when they come in handy (which so far hasn't been once on this site, but then, I've only done seven problems or so) without worrying about it.
And class variables don't use any more memory, and their functions don't either - however, virtual functions *do* use a very tiny extra amount of memory, and they can kill execution speed if they're overused, and any sort of dynamic allocation will take extra RAM (and cycles :P)
I've found in these contests that usually code running too slowly is an indication you need an algorithmic improvement, and something minor like which language you choose and whether you use classes or not won't be a problem.
And class variables don't use any more memory, and their functions don't either - however, virtual functions *do* use a very tiny extra amount of memory, and they can kill execution speed if they're overused, and any sort of dynamic allocation will take extra RAM (and cycles :P)
I've found in these contests that usually code running too slowly is an indication you need an algorithmic improvement, and something minor like which language you choose and whether you use classes or not won't be a problem.