Page 7 of 10

### Re: 713 - Adding Reversed Numbers

Posted: Mon Jan 19, 2009 7:44 am
plz help. Edited bt still WA.

Code: Select all

``removed``

### Re: 713 - Adding Reversed Numbers

Posted: Wed Jan 21, 2009 8:23 am
why , you dont check the test case of problem ?
try these

Code: Select all

`````` 24 1 (test case of problem !!!)
1 24
23 4
4 23``````

### Re: 713 - Adding Reversed Numbers

Posted: Wed Jan 21, 2009 8:47 am
Thank you.
I thought i was passing the sample test cases well.

### Re: 713 - Runtime error

Posted: Sun Aug 23, 2009 7:31 am

Code: Select all

``````#include <iostream>
#include<string>
using namespace std;
#include<algorithm>
int main()
{
int test_cases ;
int i ;
while ( cin >> test_cases )
{

string a , b ;
for ( int j = 0 ; j < test_cases  ; j++ )
{
int sum_a = 0 , sum_b = 0 ;
cin >> a >> b ;

reverse( a.begin()  , a.end() ) ;
reverse( b.begin()  , b.end() ) ;

for (  i = 0 ; i < a.size() ; i++ )
sum_a = sum_a * 10 + ( a.at( i ) - '0' ) ;
for (  i = 0 ; i < b.size() ; i++ )
sum_b = sum_b * 10 + ( b.at( i ) - '0' ) ;

sum_a += sum_b;

a.clear() ;
for ( i = 0  ; sum_a  > 0  ; i++  )
{
a  += ( sum_a % 10 ) + 48 ;

sum_a /= 10;
}
while ( a.at ( 0 )  ==  '0'  )
a.erase(  0 , 1 ) ;

if( a.empty()  )
cout << "0\n" ;
else
cout << a << endl ;

}

}

return 0;
}

``````

### Re: 713 - Runtime error

Posted: Fri Sep 04, 2009 5:09 pm

I think ur code get RTE becoz string a,b can be 200 digit long.........
so it can't be fit in int sum_a,sum_b;

Try to change this line ...............

### 713 - Adding Reversed Numbers

Posted: Thu Nov 19, 2009 9:59 am

The problem says when u reverse 1200, it becomes from 0021 to 21.
If the test case is

Code: Select all

``````1
1200 9
``````

Code: Select all

``````3
``````
Because 21+9 = 30 becomes to 3 (drop 0 out).

My first code used 0021 to add 9, and the answer was 300.
At the second time, I changed my code, and the answer was 3.
Both above codes got AC in Nov. 19, 2009 (UTC+8).
I think test cases in this problem have to be enhanced.

### Re: 713 - Adding Reversed Numbers

Posted: Wed Sep 29, 2010 10:27 pm
Hi,
can anyone tell me why am i getting WA:

Code: Select all

``````#include<stdio.h>
#include<string.h>

int main()
{
char num1[201],num2[201],tmp[201],sum[202],out1[202];
int n1,n2,carry,len1,len2,i,j,k,s,input,m,n,t,out;

carry=len1=len2=i=k=j=0;

while((scanf("%d",&input))==1)
{
for(m=0;m<input;m++)
{
scanf("%s %s",num1,num2);

len1=strlen(num1);
len2=strlen(num2);

if(len1<len2)
{
strcpy(tmp,num2);
strcpy(num2,num1);
strcpy(num1,tmp);
t=len1;
len1=len2;
len2=t;
}
i=j=0;
s=0;
while(i<(len1))
{
if(i>(len1-1))
{
n1=0;
n2=num2[j]-'0';
}
else if(j>(len2-1))
{
n1=num1[i]-'0';
n2=0;
}
else
{
n1=num1[i]-'0';
n2=num2[j]-'0';
}

s=n1+n2+carry;

if(s>=10)
{
carry=1;
sum[k]=(s-10)+'0';
}
else
{
carry=0;
sum[k]=s+'0';
}
i++;
j++;
k++;
}

if(carry==1)
{
sum[k++]='1';
sum[k]='\0';
}
else
sum[k]='\0';

if(sum[0]=='0')
{
k=i=0;
out=1;
if((strlen(sum))>1)
{
while(sum[k]=='0')
k++;
}
while(sum[k]!='\0')
out1[i++]=sum[k++];
out1[i+1]='\0';
}
if(out==1)
printf("%s",out1);
else
printf("%s",sum);
printf("\n");
carry=0;
n1=0;
n2=0;
k=0;
out=0;
}
}

return 0;
}``````

### Re: 713 - Adding Reversed Numbers

Posted: Fri Nov 16, 2012 10:21 pm
Input:

Code: Select all

``````2
999999 999999
1 999999``````
Correct output:

Code: Select all

``````8999991
1``````

### Re: 713 - Adding Reversed Numbers

Posted: Tue Jan 15, 2013 9:24 am
Deleted the code after getting AC
Thanks brianfry713

### Re: 713 - Adding Reversed Numbers

Posted: Tue Jan 15, 2013 10:19 pm
Input:

Code: Select all

``````100
265472 28458927
49507 152228
481114264 486316
3436 6744504
73583771 93751385
53 11432
1594 55519279
820686 5045
310755 315799
28689019 4648946
9137 6689998
1653804 517
43 5
74 69
719 32801
705429895 68303
31 89400657
61590028 479401397
6195 60949775
64110832 215000011
193 998949
171 85202
3969 80858
3998867353 669977
245 731012579
27867 8094
8240733 7
1061159623 3539786805
551 73
2454547635 2
48 606
329113207 5294283811
74967512 3
6955502 200310419
47865 16
51045443 18
8598335 276995244
3468316259 14
959992 8
78469946 7
51343 3421305878
548766117 6220516
6219007 12
7 3
48091 9586821
9189 786601435
2950375371 4
42695 2117
33266 33494631
7 68344463
7939048 699497
366 55
144587 2810509
3 22443
5336512745 1
10878046 919707522
802 7877953055
64 60873769
461563489 1
6858 968625
36828 711733
8578387182 965413
8768 4975
378131 8109325
73 7141
39 175337
38953 84
69824 1776
353 77
4684158 553
488636 636248
51577 4316
309870222 38429771
35 88711659
51442756 170848
66106322 62
7914864 866071872
26235 42
9 5392
3418416 9
818 6429424078
8 85
9115 6990656089
959689742 98343498
47 76
41 5061177396
866204 200746047
67 668
4717 8041476
14 7
45902 827895
45647 4
381693044 688008
717 111100686
5836 3411
55 2
15300095 184062
3585601 6121
7552269 45391
412924 4351``````
AC output:

Code: Select all

``````44006237
548298
868420364
9180604
67245067
64432
60569279
334196
6254551
64179579
5817009
6724804
93
341
4711
398459895
11500657
94411578
22800875
856108331
92059
92402
10559
9598648353
976012579
8718
5340733
4590936538
291
4454547635
96
8486316881
5967512
895860619
53965
69045443
36839744
4868316259
769992
49469946
8555605878
170818717
7419007
1
3495031
605611435
6950375371
63766
66651731
39344463
3934029
817
3265389
52443
6336512745
27597982
5997953055
25873769
561563489
554535
89914
7233518182
27441
1980735
4541
466337
13063
76694
34
9125158
259741
94638
683178932
14811659
68427566
29106322
568458282
68235
4492
2518416
4600524078
66
5116656089
843124733
141
9161177396
76940147
249
2858476
84
286916
85647
960791144
828100686
8257
75
23806295
9607601
1191469
847034``````

### Re: 713 - Adding Reversed Numbers

Posted: Thu Jan 17, 2013 11:59 am
@ brianfry713 , Thanks for your reply . But I'm still getting WA. There was a problem for this input : 265472 28458927 . I fix it but still WA

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{

int N;
scanf("%d",&N);
for(int k=0;k<N;k++)
{
int b1[210],b2[210],sum[210],c=0,ln1,ln2,chk,max=0,diff=0;
char str1[205],str2[205];

scanf("%s %s",&str1,&str2);
ln1=strlen(str1);
ln2=strlen(str2);
int j=0,m=0;
max=ln2;
for(int z=0;z<(abs(ln2-ln1));z++)
{

if(ln2>ln1)
{

b1[j]=0;
j++;
}
else
{
max=ln1;
b2[m]=0;
m++;
}

}
for(int i=ln1-1;i>=0;i--)
{
b1[j]=str1-48;
j++;
}
for(int i=ln2-1;i>=0;i--)
{
b2[m]=str2-48;
m++;
}
int count=0,chkp=0,aa,bb=0;
for(int i=max-1;i>=0;i--)
{
sum=count+b1+b2;

if(sum>9 && i!=0)
{
count=1;
sum=sum%10;
}
else
count=0;

if(sum%10==0)
sum=sum[i]/10;
else if(sum[i]>9)
{
aa=sum[i]%10;
sum[max]=sum[i]/10;
sum[i]=aa;
bb=1;
}

if(chkp+sum[i]!=0)
printf("%d",sum[i]);
chkp+=sum[i];
}
if(bb==1)
printf("%d",sum[max]);
printf("\n");
}
return 0;
}

### Re: 713 - Adding Reversed Numbers

Posted: Thu Jan 17, 2013 10:11 pm

Code: Select all

``````100
18846 29
3 539
6371812887 345499277
895 6255126497
323 22138854
75963 8577219978
5 59
42 7671811
6 38
451162048 5822434
918 5514665422
870976 721077626
1831 89257874
42932 890117171
24411086 8023
71 9386
18487587 257886
9331576856 910180694
1046735648 29948532
64067 1229519273
75201 73
53 485002
25 727832
499 94
171 3496278311
46486 65
94333 12752698
11192 18616242
25679 28743229
3997054 959372
198499085 833
8 594
64 904933464
98556 77997
6870991406 1189665
714 21
1 8108
9519979126 9725
1257165 10100626
5141 870201
143 5
78837847 903
7609876 7916179774
919505334 2502797
13666472 2383106
9 8
21 7633759
52 92137772
4 87790227
7564446156 88688
75072776 52056129
60407155 4291
21868 984102927
2 2643719
910629 53
137567956 638
6 19835
623786 3112
420791216 674
7919687 102836114
368486 569297
119691679 667193345
204571596 9059670564
61382 89
145 83
180582093 41
61277 8515541834
9362 77054
9360485 6862316492
84159114 4622986
136714042 7
8 762383461
674 26761557
38888706 5916465
1591791 611239
71021 85
201 6073586
65246477 49
5804 2549216409
6766293954 938
4931121 232
22393083 1454688979
7580870209 26791798
297477292 3625805
74304 84263696
155604365 879010655
53 441912
3 151016646
94 1749
111 12185406
2 47
798562457 46
21424 483008
22 66
997 85
917783038 98
133656 7
6485588 2824824
97110568 925
486 463844556``````
AC output:

Code: Select all

``````37946
839
9726715568
4216126497
54438854
5174619978
1
1971811
98
934306448
4794665422
502944726
97667874
220537171
5641086
6586
33276297
8532382807
3931698848
7625329273
49201
916002
977832
3401
4117278311
2586
7095698
29709242
43423329
2591874
922599085
305
554933464
665541
7950667406
924
9108
8344089126
22671286
394301
643
69147847
4625056874
179774144
36408433
71
9733759
45137772
28790227
5433356156
280298951
3327155
103882927
4643719
450629
765667956
79835
934986
5791216
893705914
8287741
7768859151
1194495435
41482
975
590582093
4732351834
61774
5233791592
21478084
836714042
572383461
83271557
87053466
7604092
57021
8083586
5346477
7353316409
5157293954
6261121
3683096389
9160050119
550068792
59567696
9257149111
971912
451016646
259
23285406
67
169562457
697248
88
758
808783038
833656
82104131
80710568
840944556``````

### Re: 713 - Adding Reversed Numbers

Posted: Wed Jan 23, 2013 7:41 am
@ brianfry713 , I got correct answer for all of your given input. but I'm still getting WA

### Re: 713 - Adding Reversed Numbers

Posted: Thu Jan 24, 2013 2:55 am
Input:

Code: Select all

``````1
499 94``````
AC output:3401