Bigint

Write here if you have problems with your C++ source code

Moderator: Board moderators

ftomi
Learning poster
Posts: 64
Joined: Sun Jan 06, 2002 2:00 am
Location: Hungary
Contact:

Bigint

Post by ftomi » Thu Apr 11, 2002 10:26 pm

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?

Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:

Post by Stefan Pochmann » Fri Apr 12, 2002 3:10 am

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.

ftomi
Learning poster
Posts: 64
Joined: Sun Jan 06, 2002 2:00 am
Location: Hungary
Contact:

Post by ftomi » Fri Apr 12, 2002 8:27 am

I'm also making an own class. The problems are not that I don't know C++ enought, I'm only a bit lazy. I don't want to write, if there is already reachable on the net. (What I found, thoses are so worse)

C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

Post by C8H10N4O2 » Sat Apr 13, 2002 9:42 pm

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.

Alexander Denisjuk
New poster
Posts: 35
Joined: Sat Jan 05, 2002 2:00 am
Contact:

Post by Alexander Denisjuk » Thu Jun 27, 2002 10:55 am

Stefan 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.
Wellcome to 288th problem :wink:

User avatar
Moni
Experienced poster
Posts: 202
Joined: Fri Mar 22, 2002 2:00 am
Location: Chittagong. CSE - CUET
Contact:

Post by Moni » Mon Oct 21, 2002 9:42 pm

I think Classes are not good for online solve submissions! Agree? :-?
ImageWe are all in a circular way, no advances, only moving and moving!

Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:

Post by Stefan Pochmann » Tue Oct 22, 2002 2:49 am

I disagree. Why don't you like classes? They're a way to make your code cleaner, which can lead to code with less bugs and that you understand and finish faster. Plus, if you do it right (i.e. use a nice interface) they are perfect for ready-to-use-for-copy-and-paste.

ec3_limz
Learning poster
Posts: 79
Joined: Thu May 23, 2002 3:30 pm
Location: Singapore

classes...

Post by ec3_limz » Fri Oct 25, 2002 2:18 pm

I uses struct instead :D but without any functions.

Yes I agree that classes make your code cleaner. Use them whenever you need to.

User avatar
Ming Han
Learning poster
Posts: 77
Joined: Thu Jun 06, 2002 7:10 pm
Location: Singapore
Contact:

Hi

Post by Ming Han » Fri Oct 25, 2002 5:43 pm

Hi ec3_limz !!

Although classes "make your code cleaner",
some people don't like to use classes.

Can you give me any examples where you use classes in ACM (because I don't remember seeing you using classes on your code) ??

HAHA.
:: HanWorks ::

User avatar
Moni
Experienced poster
Posts: 202
Joined: Fri Mar 22, 2002 2:00 am
Location: Chittagong. CSE - CUET
Contact:

Post by Moni » Fri Oct 25, 2002 10:47 pm

Actually I wanted to mean that classes take more time to code and though it can be pasted but it will take more memory space and also you can get run-time errors or time-limit-exit.
ImageWe are all in a circular way, no advances, only moving and moving!

Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:

Post by Stefan Pochmann » Sat Oct 26, 2002 12:04 pm

Classes can make code cleaner and take *less* time to code. And why should they take more memory? And you can get run-time errors and TLE without classes just as well.

User avatar
Moni
Experienced poster
Posts: 202
Joined: Fri Mar 22, 2002 2:00 am
Location: Chittagong. CSE - CUET
Contact:

Post by Moni » Sat Oct 26, 2002 8:34 pm

:-? Isn't class variables and functions share more memory than simple string processing with pointers? :roll: 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 ! :wink:
ImageWe are all in a circular way, no advances, only moving and moving!

zorbathut
New poster
Posts: 16
Joined: Tue Nov 05, 2002 6:31 am

Post by zorbathut » Tue Nov 05, 2002 6:46 am

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.

Fresh
New poster
Posts: 46
Joined: Mon Apr 15, 2002 10:42 am
Contact:

...

Post by Fresh » Wed Nov 27, 2002 3:34 am


zorbathut
New poster
Posts: 16
Joined: Tue Nov 05, 2002 6:31 am

Post by zorbathut » Wed Nov 27, 2002 3:41 am

Probably the best example I've ever seen of a library that needs operator overloading ;) Maybe I should write a wrapper class . . .

Post Reply

Return to “C++”