## 713 - Adding Reversed Numbers

Moderator: Board moderators

alright the stupid judge uses gcc 2.95

fixed now :p
n00i3
New poster

Posts: 20
Joined: Thu Sep 15, 2005 8:49 pm

Input:

100 200

999999999999999 1

00010 9

1 9

1 9

5 5

456 654

0 0

Output:

3

1

9001

1

1

1

111

0
mhayter1
New poster

Posts: 15
Joined: Wed Jul 26, 2006 10:00 am

### very easy

it is not so difficult;
adding reverse but no need to reverse;
add two string from left side to right side normal
print then canceling first 0 digit

input:-

101
99
out put -
2

[/code][/b][/list][/list]
mak(cse_DU)
Learning poster

Posts: 72
Joined: Tue May 30, 2006 5:57 pm

### 713-WA- help! help!! help!!!

:roll:
here im having WA. but for all the inputs i tryed i got right output pls help. here is my code.

-------------------------------------------------------------------------------------

Code: Select all
`#include<stdio.h>long int power(long int b,long int p);long int revint(long int a);void main(){   long int t,a,b,i,fa,fb,fab,ffab;   while(scanf("%ld",&t)!=EOF)   {   for(i=1;i<=t;i++)   {      scanf("%ld%ld",&a,&b);      fa=revint(a);      fb=revint(b);      fab=fa+fb;      ffab=revint(fab);      printf("%ld\n",ffab);   }   }}long int power(long int b,long int p){   long int i,result=1;   for(i=1;i<=p;i++)      result*=b;   return(result);}long int revint(long int a){   long int i,mod,m[50],j,fa=0,k;      for(i=1;a!=0;i++)      {         mod=a%10;         m[i]=mod;         a=a/10;      }      for(j=i-1,k=0;j>=1;j--,k++)         fa=fa+m[j]*power(10,k);   return(fa);}   `

nahid
New poster

Posts: 18
Joined: Wed Oct 04, 2006 8:59 pm

the problem description mentioned
Numbers will be at most 200 characters long.

and also the number may contain leading zeroes.
Code: Select all
`03425 3455`

i solved by this way-[list][*]input in a string
[*]normally we add two number right to left. here add left to right. as a result this add reversely.
[*]the number may contain leading zeroes. But don
[ Common thing of every man is that, everyone thinks that he is uncommon ]

Tariq Shahriar
New poster

Posts: 17
Joined: Wed Mar 01, 2006 8:34 pm
Location: 2nd floor

### Please, here is some test, give me the right output

Guys, My program receveid WA, and i don't know why, i have generated some test and my output for these test, but it's not right, Does anybody can give me the right output?

Input
Code: Select all
`500139144 39097186290 72395265374 15315252337 299805112027 383722254786 10146465053 192248150698 196960440760 312400305979 285456313564 333849309019 141815368890 267849216173 262773150326 61110375936 67036376378 95972311248 15125029394 324927132454 131380321546 346713333896 248003294732 441492171118 89249154480 433109239199 293352331379 37096408296 92050137378 46904032316 473418347200 450963398419 144658272712 16579188000 264547365904 27612286896 486329492327 468804391013 106355266668 100933199208 475299332535 74319335558 21651276239 395077443899 141052495763 7361193641 49056372445 229132112345 183847418020 13075952669 91458270664 28673279394 256020434216 420124302470 7902668139 2686425424 141137252249 8651482023 80081462542 360309422717 140863303178 220038406732 266695134126 28429110096 157782148631 137143273545 137638449883 176707223714 91279267559 66830165631 35132015775 29114158387 228464229727 33271158326 4541237116 475349458031 150199299634 336083192509 354360299747 394552177869 62211294707 298840470888 2018525396 487023364540 444929161073 93221463647 274538144871 16660203159 19115285910 5661377699 171716487410 44630494060 304083376199 22640749934 62803216105 35563465645 438684328919 417640395413 447751392305 185838365511 358971424828 100019416977 21812179753 389452366335 490784235495 432324280960 957415089 34187731060 476616114274 100183333683 79807418875 103348186469 234144188521 91898355579 323979273948 15328470286 35812423990 37332392969 428121104344 229465114609 3598655749 193578107757 395595422640 8888819880 333268375624 174596317612 292269220278 492404100530 227495109342 89463483868 122029162708 164064155468 343239317428 438175121008 25871130512 157916490053 305514319162 46814244218 230722169187 34307328262 121009486728 191220477513 487557353218 358392218975 384213115418 481329225535 25896145427 20840173760 474386305253 189969207897 257273402210 132077471980 171264239077 9460852596 119214330913 166972105741 375793321901 1145282344 469413156168 150175400374 10624497952 364129295330 440322237352 98578344231 287624393127 237112474781 33482305646 92468315442 126563187469 4724979172 43853314818 285866359558 77655291583 280998365808 296253481668 32501145626 433257261637 81321190027 9712115995 317114447 11838356944 312581197925 483599169824 331639153606 265410325044 393314451363 468950333441 211510464825 43051526261 23352167486 246241261681 327143445349 180946133032 347880495941 439935212458 4363061445 386276260720 440912108539 36532434811 386027387730 88393324442 34141349395 205173238376 493144338716 304671441552 317174492 144010203988 46888214359 10169179670 217337196915 302057282640 367367442351 44112207501 2533556926 209821304766 14250233812 290201173357 395584310764 175934342149 175346147566 287117101828 165991302535 36893474872 219053444082 167435163502 7240276360 2854713477 402449158871 182618137086 324915386961 291918411242 85185288116 25155167995 18412203090 402000317944 40225780364 147735202816 31178657527 104995367147 401861494125 420066287392 147355486099 3730455334 1881365139 31907332152 457226193366 26588681729 225079162327 454241180810 6014676253 3262320031 449552288769 411624498758 126496359544 193406189668 373668354114 24646812227 122065133811 179544225100 435079190345 105469266179 191948471361 348450445608 140610118029 12132510951 183109239456 218594174430 430992400469 471196209245 454921185785 456301403667 352151426924 153375272150 33541224861 189132466918 282505195967 45762041670 370321189809 193074369621 312785431625 355163483166 197840106219 20975964125 440253476759 181607324017 116683340764 1918478200 338061391939 178042392046 348167208517 19842719814 32269466055 5214205806 440441384747 11203674430 324687394244 4298269429 21340949608 164452100744 26760266251 44069292126 28497434480 124913275479 356332425299 365917495196 395160332119 418583134853 68806201612 29445130464 136333386125 12142832877 292422200133 409189757 426658489283 99121359594 442378491326 91733477263 69581144 31818213440 287939203991 313828275945 20448427695 162861294535 64090210517 253309190516 214816496858 279640168662 94604103680 357938484128 262629241187 8743199904 427596434737 87041127427 16568360786 262312376687 328527144161 338065159982 282560285686 207952268378 214582394 111901240045 64484418493 190188289405 17374829791 159252402706 297927459361 154133310397 462817303999 173819187410 8630433895 150688137997 323395299815 444482249083 340323116327 203831185737 45926161791 38306993374 4770796429 48401663621 4041912574 300678423245 463586437251 33088211917 9152428052 363510223890 320224482655 173908411985 222963382933 6275183693 23799834110 197373461087 341958124176 160835195862 274515412286 386970362961 3144774618 443778484012 429999275653 307300188001 119371130019 47062396859 70474376540 463871228176 2262348252 59722307169 203661467455 46510989409 294258214414 9702140981 80638237779 358899187666 425169106846 456337345301 295600483811 32588772381 695717100 25247169554 223859310899 163389289230 166630408117 86199486446 366649132121 12324255347 25770426920 490215272234 58137463217 304087364828 30151285208 291607193416 26492663887 80576325334 102099155551 478334271497 117044437190 497882485078 14989436421 339999271057 381762390811 43319984345 120232202065 350898488079 10607319716 46353750118 358727138663 407086378875 28577162286 383703479622 251781319729 183954211091 276526393216 311346474505 450600437006 236414451509 122764467825 34261394177 31125541842 366503436186 272854380509 159009125591 43519305577 26126192225 16483626581 354084415031 28245922210 364085382565 374664478809 469171445753 126903329195 8460154517 281342298201 152090214739 277414421675 61226181387 43477763301 20357159126 416823421907 180584353627 195966143307 56094479341 89179305218 328650137895 167805116163 256433186486 169186252955 395513476935 34724220932 433443471850 258326186311 383859417059 343095264946 20052838336 475875162536 391190187878 308196893 235486496851 57974458267 423578244536 150402366546 458332152170 110595227112 2034479594 286870373462 366198161143 149548129788 457341166266 172829446924 342722234405 461323329563 415332214501 423052279441 488250206310 172835497394 40722025390 30521112597 366474219514 202182173858 20861240830 379049315177 477896258179 485267475460 435190`

My Wrong output:
Code: Select all
`42012580025131942544224214957493551511743778247569752175804361646314144092415267401478847761426946207236109462498518877263735667269571999636135964509587589423542160224013387965964197965787971734331771338414555475321346632261851231149736836650215655971856265411785623071584842113296358411259167729519215487794402814573054264158543301363184004139537728389630057238411562580152310716624383193182576532758743012831516690114541582695941795134989170234555154750352660355515091211526718447869584300179997948365767164119177237094794283638185120158139420017421584861782481798044592696128475618399414573566973327447814316145925248371624109870927570201667710114896756857178622621435832754511224131160417512678459132713316009450333711190132380014635741668488492353121153142217844022115009711613672132792699308250688712277621498697174569313797194521467955677773056728034032511304629578948855170160260115922985967371473506343928112096484223145417115342875431551851586342844968954705454354116428572072341506519244749636652123143522955521339709512239237431016550957135583599684136119472482155216117076785788731848477222742210625285487103257152514905631319026619358810324544951894340149514181111258872552629514709138259866487541421876601642463959711938171776658525445696225111632497758623583316618711244192904147498962154001888347145095176819144627852932146983214856094184851325773126672016605756839265025188875229490817491592315994510021578889272003430766242126605097191021940485513503167917676890981518113257487501351612639604647787463591531423601517568781289873769583699393151525514430501453337159067212442362034656502792957051358028171081258522823934412827194470511505333871556165327653219675571957920015085623288426494231543697786031273973167141778678857101730507819140455836614307901432515211614600811631204139604414118351919564525749677317898771417011653195515333673561311147700755830452280217802171781357740792171391449507226679740854315112036091335064161381593791963131965673363139523312449516720147933658946783544546381613053321666509157034506296477471264875175011215157282118523009694215147222733255348264947297893485188488550957213532531347272699633150459477211514767191941515834841450393163430858930731916853500999008931181013791640402557088886722176704213612778166254302555656316338599005537393943947370393612849021360487798167676349805588804012157206329747250163216723417304224444011323525008211823654199249194624215201585679150382615522831531011709609329539624718193001473189134696279018743195125536140315781714575450576729416653484778051358342144364142732415249853884321825083525969765421155371017249011963682552854158414315517978598085357401554656446989621414492783148751860555218251156635101573273170054826292677403360993114306081550782566738257061151099469748015861856571301838080156176617520672741334139148125314383651606518365819080935024911449593160425727114262396829470113626962466631548478714285653385620286460270175014514644741759146454627485088104427966602871836139493871597826266642065914638630651120178115761301239095178865669572873499563755365879137815589461555812148145541179637157851097978207416344371801651`

Thanks
sfelixjr
New poster

Posts: 9
Joined: Wed Apr 25, 2007 3:29 pm
Location: Brazil

Ami ekhono shopno dekhi...
HomePage
Jan
Guru

Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm

### What should i do?

Man, what the hell is going on with UVA ???
I get WA over and over again.
Can u give any advice to fix this problem?

Does anybody can see my Java code? I give up
Code: Select all
`Solved`
Last edited by sfelixjr on Wed May 30, 2007 2:54 pm, edited 1 time in total.
sfelixjr
New poster

Posts: 9
Joined: Wed Apr 25, 2007 3:29 pm
Location: Brazil

### Re: What should i do?

sfelixjr wrote:Man, what the hell is going on with UVA ???
I get WA over and over again.
Can u give any advice to fix this problem?

There is no problem with uva (for this problem) I think. May be your code is not fully correct. Try the cases.

Input:
Code: Select all
`21000 10002000 2000`

Output:
Code: Select all
`24`

Hope these help.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru

Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm

Jan, thanks, it was the only case that was wrong!!
I got AC
sfelixjr
New poster

Posts: 9
Joined: Wed Apr 25, 2007 3:29 pm
Location: Brazil

### WA 713 - Adding Reversed Numbers. Help me plz!!

I checked and rechecked along with debugging my code many times, but could not find where the bug is. I developed my own big_int class and tried to solve the problem with it. Here I am only giving the body of the methods used in main function. Would you plz see my code and tell me where I am doing the mistake. I also checked for several test datas found in this thread. Thanks in advance, I really need ur help..

Code: Select all
`#include <string>#include <iostream>#include <cstdio>using namespace std;class big_int{public:   string num;protected:   big_int operator+(string a)   {      big_int s;            s = num + a;      return s;   }   big_int operator+(char* a)   {      big_int s;      s = num + a;      return s;   }public:   big_int(){num = "";}   big_int(string a){num = a;}   void reverse(); //ok   void remove_0();   size_t size(){return num.size();}   string get(){return num;} //ok   //*string get_ref(){return &num};   big_int root();   big_int operator=(big_int a); //ok   big_int operator=(string a); //ok   big_int operator=(int a); //ok   big_int operator=(char *a); //ok   big_int operator+(big_int a); //ok   big_int operator+(int a); //ok   big_int operator-(big_int a);   big_int operator-(int a);   big_int operator*(big_int a); //ok   big_int operator*(int a);//ok   big_int operator/(big_int a);    big_int operator/(int a); // ok   bool operator<(big_int a);//ok   bool operator>(big_int a);//ok   bool operator==(big_int a);//ok   bool operator!=(big_int a);//ok   bool operator<=(big_int a);//ok   bool operator>=(big_int a);//ok};big_int big_int::operator=(big_int a){   num = a.num;   return *this;}big_int big_int::operator=(string a){   num = a;   return *this;}big_int big_int::operator=(int a){      num = "";   while(a)   {      num.push_back(a%10 + '0');      a /= 10;   }   reverse();   remove_0();   return *this;}big_int big_int::operator=(char* a){   string b = a;   num = b;   return *this;}big_int big_int::operator+(big_int a){   int len, len_a, carry, i, j, add;   len = num.size();   len_a = a.num.size();   big_int s("");   carry = 0;   i = len-1;   j = len_a - 1;   while(i>=0 && j>=0)   {      add =   num[i--] + a.num[j--] - '0' - '0' + carry;      s.num.push_back(add%10 + '0');      carry = add/10;   }   while(i>=0)   {      add = num[i--] - '0' + carry;      s.num.push_back(add%10 + '0');      carry = add/10;   }   while(j>=0)   {      add = a.num[j--] - '0' + carry;      s.num.push_back(add%10 + '0');      carry = add/10;   }   while(carry)   {      s.num.push_back(carry%10 + '0');      carry /= 10;   }   s.reverse();   s.remove_0();   return s;}void big_int::reverse(){   int i, j;   j = num.size() - 1;   for(i=0; i<j; i++, j--)      num[i] ^= num[j] ^= num[i] ^= num[j];    return;}void big_int::remove_0(){   if(num[0] == '0')   {      int i = (int)num.find_first_not_of('0');      num.erase(0, i);   }   if(num.size() == 0)      num = "0";   return;}char a[250], b[250];int main(){   int i;   big_int n1, n2, sum;   scanf("%d", &i);   while(i--)   {      scanf(" %s %s", a, b);      n1 = a;      n2 = b;      n1.remove_0();      n2.remove_0();      n1.reverse();      n2.reverse();      sum = n1 + n2;      sum.reverse();      sum.remove_0();      cout<<sum.num<<endl;      /*int len = sum.num.size();      for(int j=0; j<len; j++)         printf("%c", sum.num[j]);      printf("\n");*/   }   return 0;}`
anowar_jaman
New poster

Posts: 2
Joined: Mon Sep 29, 2008 4:14 am

### Hints:713 - Adding Reversed Numbers

Those who wants some hints:

1. for input like 1000 1, my output is 2000.
2. for input like 1000 1000, output is 2000.
3. for input like 00010 9, output is 90010.
4. No need to reverse at all.

And, I got AC in 0.000.
naffi
New poster

Posts: 23
Joined: Wed Mar 19, 2008 12:25 pm

### Re HINTS : 713 - BUT Hints !!!!

But my AC code give different output :

for 1000 1 output = 2
for 1000 1000 output = 2
for 00010 9 output = 9001

I think my procedure according to the problem description is OK.
tanvir_cse
New poster

Posts: 9
Joined: Wed Jul 09, 2008 10:12 pm

### Re: 713 - Adding Reversed Numbers

Code: Select all
`removed`
Last edited by Obaida on Sat Jan 03, 2009 6:27 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.
Obaida
A great helper

Posts: 380
Joined: Wed Jan 16, 2008 6:51 am

### Re: 713 - Adding Reversed Numbers

Your code has problems with zeroes

try 0 0
ExUCI
New poster

Posts: 14
Joined: Sat Aug 12, 2006 3:31 am
Location: USA

PreviousNext