Манипулирование с целыми числами произвольной длины

Ninnaacnu kaiis lsioaaos gakcloecsiaakc? n oaeugc ?cneagc
lsiceaieukie aecku. Lsioaaosu aieeku iianla?caanu: oisgcsiaakca c aaia oaeuo
?cnae lsiceaieukie aecku, neieakca, au?cnakca, nsaakakca c ogkieakca oaeuo
?cnae. Saiininliniikinnu lsioaaos lsiaagiknnscsiaanu ka aagiknnsaocikkie
lsicsagga. Giaoeu, saaeceozlce
oaeua ?cnea lsiceaieukie aecku, c nanniaa? lsicsagga kalcnaku ka ?euza N++.
Ae? lsaannaaeakc? oaeuo ?cnae lsiceaieukie aecku ilsaaaeak zeann UNLIM.
Ilasaocc kaa zncgc ?cneagc saaeceiaaku lonag lasailsaaaeakc? ae? zeanna UNLIM
neaaozlco ilasaoce: > Ainieznka? aaec?cka ?cnea lsiceaieukie aecku
osakcnn? a lag?nc a acaa ganncaa ncla CHAR. A zaeaig zeagakna ganncaa giean
kaoiacnn? ?cnei in 0 ai 99, ni annu aaa saes?aa anaci ?cnea. A koeaaig zeagakna
osak?nn? geaauca aaa saes?aa, a lineaakag zeagakna - nnasuca aaa saes?aa. Anec
?cnei cgaan ka?ankia ziec?annai saes?aia, ni a lineaakag zeagakna ganncaa
osakcnn? iack lineaakce saes?a, n.a. ?cnei in 0 ai 9. Ecacsozlca koec a ganncaa
ka osak?nn?. ?cnei 0 lsaannaaeaki ganncaig ce iakici zeagakna, a zinisig
osakcnn? 0. N oaeuz gckcgcecsiaanu zilcsiaakca c sanoia lag?nc zeann
UNLIM saaeceiaak naz, ?ni ka iaki lsaannaaeakca ainieznkie aaec?cku gicon
nnueanun? kanzieuzi ?cnae, lsc znig aaaann? o?an nnueiz. Iisazn zeanna
UNLIM ninnicn ce lie? SIGN - ekaza ?cnea c lie? PV - ozaeanae? ka aanzsclnis
lsaannaaeakc? ainieznkie aaec?cku. ?cnei 0 anacaa cgaan ekaz PLUS.
Aanzsclnis lsaannaaeakc? ainieznkie aaec?cku ?cnea lsaannaae?an niiie iisazn
nnsoznosu DESCRIPTOR c cgaan neaaozlca lie?: len - aecka
ganncaa body[] a iaenao; Ce ilasaoce
nsaakakc? nieuzi < c != kals?goz nsaakcaazn ?cnea, innaeukua ilasaocc
ausaeaku ?asae znc aaa. Lsc saiina ilasaoce < c != nka?aea lsiaas?znn? ekazc
c aecku ?cnae, c nieuzi a neo?aa co nialaaakc? lsiceaiacnn? lisaes?akia
nsaakakca ?cnae (a za?annaa saes?aia eaanu iasonn? oaeua iaenu - n.a. saes?au a
ncnnaga n?cneakc? n inkiaakcag 100).
Ilasaoc? okaskue - aieasalaan kiaue iisazn zeanna UNLIM, zinisue nnueaann? ka ni
ea lsaannaaeakca giaoe? ?cnea, ?ni c ascogakn, c cgaan ekaz, lsincailieiekue
ekazo ascogakna. A lasaig neo?aa
ekaz saeoeunana niinaannnaoan ekazo iakici (eziici) ce ilasakaia, a giaoeu
saeoeunana ?ae?ann? saeoeunanig neieakc? giaoeae ilasakaia. Lsc znig anec
ziec?annai saes?aia lasaici ilasakaa saaki A, a anisici - B, ni ziec?annai
saes?aia ilasakaa giean iunu ecii max(A,B), ecii max(A,B)+1, liznigo lsc
auaaeakcc lag?nc lia gannca ae? giaoe? saeoeunana iasann? anisia eka?akca.
Kczazie ilncgceaocc znici ganncaa linea neieakc? giaoeae ilasakaia ka aaeaann?,
naz zaz a aakkig neo?aa linas? lag?nc ka ecacsozlca koec giean iunu gazncgog 1
iaen, c auciakaa nzzikigcnu ka nzisinnc, ?ag ka lag?nc. A neo?aa, zicaa
ekazc ilasakaia saeec?ku, ekaz saeoeunana saaak ekazo ilasakaa n gazncgaeukug
giaoeag, a giaoeu saeoeunana lieo?ann? au?cnakcag giaoe? ilasakaa n gckcgaeukug
giaoeag ce giaoe? ilasakaa n gazncgaeukug giaoeag. Lsc znig lia giaoeu
saeoeunana auaae?ann? gannca aecku, saakie kaciieuuae ce aeck ilasakaia, ki
linea au?cnakc? ?cnae ik ilncgcecsoann? ookzocae optimize(), zinisa? oaae?an
ecacsozlca koec (nieaaan kiaue gannca aecku, kaiioiacgie ae? osakakc? giaoe?
?cnea iae ecacsozlco koeae, zilcsoan a kaci ana eka?alca saes?au,
lasaaasaniauaaan nnuezo aanzsclnisa ka znin gannca c oaae?an nnasue gannca).
Ilasaoc? ickaskue - ilsaaaeaka ?asae okaskue gckon c
ickaskue lezn. Ilasaoc? * lsiceaiacnn? li naokieiccc, akaeicc?kie
ogkieakcz a nnieicz. Lsc znig ana aaennac? aaaonn? a ncnnaga n?cneakc? n
inkiaakcag 100. Aecka ganncaa saeoeunana giean iunu saaka ecii nogga aeck
ilasakaia, ecii znie nogga gckon 1. Zna ncnoaoc? akaeicc?ka nie, zinisa? iuea
lsc neieakcc ?cnae n iackaziaug ekazig, c eaanu niea ka aaeaann? ilncgceaocc.
Ilasaoc? << - lsinni ilasaoc? auaiaa zeanna OSTREAM, ilsaaaeakka?
ae? zeanna UNLIM. Nka?aea ika auaiacn '-' anec ekaz ?cnea inscoanaeukue, a eanag
nagi ?cnei lisaes?aki (li aan?nc?kug saes?aag), ka?cka? ni nnasuaci. Lsc znig
cnlieueoann? ookzoc? digit(number), zinisa? aieasalaan eka?akca aan?nc?kici
saes?aa n kigasig number. Ookzoc?- ziknnsoznis unlim(char*) iisaianuaaan
ckcocaeceaocz ncgaieukie nnsizie. Lsc znig sanliekaznn? neaaozlca iucii?kua
ncnoaocc: ckcocaeceaoc? lonnie nnsizie; kaailonncgue ncgaie a nnsiza; nnsiza
niaasecn ekaz, ki ka niaasecn eka?akc?. Ai anao znco neo?a?o ?cnei
ckcocaececsoann? koeag. In?an nanniaie
lsicsaggu Ckcocaeceaoc? nnsizie: unlim e="+" Unlim class error: Sign without
value. Value=0 unlim g="aaa" Unlim class error: Not digit
symbol in string. String ignored. Value=0
h=0 a=123 a=+0000000000000000123 a>b
a>=b a!=b b=-45 b=-45 a+b=78 a-b=168 a*b=-5535
a<b a<=b a!=b b=999999999999999999999999999999999999999999999 b=999999999999999999999999999999999999999999999 a>b a>=b a!=b
a+b=1999999999999999999999999999999999999999999999 a-b=1
a*b=9999999999999999999999999999999999999999999990000000000000000000000000000000
00000000000000 b=999999999999999999999999999999999999999999999 b=999999999999999999999999999999999999999999999
a<b a<=b a!=b
a+b=899999999999999999999999999999999999999999999 a-b=-
1099999999999999999999999999999999999999999999 a*b=-
99999999999999999999999999999999999999999999900000000000000000000000000000000000
000000000 a=0 +a=0 #include <iostream.h> #define CR "\n" cout<<"\nNanniaa? lsicsagga ae? zeanna
UNLIM\n" r<<"In?an nanniaie
lsicsaggu\n" r<<" unlim a;\n"; <<"
Ckcocaeceaoc? nnsizie:\n" r<<" b="<<b<<CR r<<"
c="<<c<<CR r<<" d="<<d<<CR <<"
unlim g=\"aaa\"\n"; <<" unlim h=\"4a123\"\n"; <<"Lsiaasza auaiaa, ascoganczc c
nsaakakc?:\n\n"; cout<<"\nAaiacna iaki ea asoccg 2 ?cnea;
ae? izik?akc? - iia
koec\n"; <<"
b="<<bb<<CR r<<" a="<<a<<CR<<"
b="<<b<<"\n\n" if (a<b)
r<<"a<b "; if (a>=b) r<<"a>=b
"; r<<"\na+b="<<(a+b)<<CR <<"\n\n--------------
------------------------------------
\n\n" #define FALSE 0 public: &operator =
(char*), operator !=
(unlim&,unlim&), operator <
(unlim&,unlim&), operator - (unlim&,unlim&),
// binary &operator <<
(ostream&,unlim&); }; char NotDigit(),
//message "no digit" & init0 inline int
operator ==(unlim &a,unlim &b) return (a<b) !(a!=b); inline int operator >(unlim &a,unlim
&b) return
x; #include <string.h> #define ILLEGAL
10 unlim(); &operator = (unlim&); operator >
(unlim&,unlim&), operator <=
(unlim&,unlim&); operator - (unlim&), // unary operator *
(unlim&,unlim&), private: descriptor char
&operator [](COUNT i) {return pv->body[i];} optimize(), //optimize length of body cout <<"Unlim class error: " (pv->body)=new char; { if
(number%2==0) pv=new
descriptor; if (
isdigit(symbol) ) pv=new
descriptor; error("Empty string
assigned.
Value=0"); init0(); if ( (Length-=LeftLimit)==0
) (pv->body)=new
char[DestLength]; char
a=DecVal(string[si]); if (si!=LeftLimit) void
unlim::NotDigit() init0(); sign=arg.sign; if ( --(pv->HowMany)==0 ) return
*this; ostream
&operator<<(ostream &s,unlim &x) s << int(x.digit(i-1)); if (
(a.pv)->len != (b.pv)->len) COUNT length=((a.pv)-
>len)/2+((a.pv)->len)%2; int
operator<(unlim &a,unlim &b) { return FALSE; return ( aLess && SignPlus) ( !aLess &&
!SignPlus ); SignPlus= a.sign==PLUS; inline int operator ==(unlim &a,unlim
&b) return (a<b)
!(a!=b); inline int operator
>(unlim &a,unlim &b) return
x; unlim operator -(unlim
&x) unlim y=x; void unlim::optimize() { delete pv-
>body; if
( (pv->body[i]/10)==0 && (pv->len%2)==0 ) if
(a.sign==b.sign) alen=(a.pv)->len/2+(a.pv)-
>len%2, (r.pv)->body=new
char[rlen]; unsigned char sum=( i<alen ? a[i] : 0)+(
i<blen ? b[i] :
0); (r.pv)->len--
; bb=a; blen=(bb.pv)->len/2+(bb.pv)-
>len%2; *(r.pv)->body=0; if (sub<0) r.optimize(); } if
(a.sign==b.sign) alen=(a.pv)->len/2+(a.pv)-
>len%2, (r.pv)->body=new
char[rlen]; unsigned
int i
f ( r.digit((r.pv)->len-1)==0 )