## 713 - Adding Reversed Numbers

Moderator: Board moderators

### Re: 713 - Adding Reversed Numbers

I think a simple mistake leading me to Wa. Some one please give me some test case.
I got several wa in this problem.

Code: Select all
`removed`
Last edited by Obaida on Mon Jan 19, 2009 7:44 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

try this
Code: Select all
`999 999`

ans is 1998
Impossible says I`m possible

vahid sanei
Learning poster

Posts: 84
Joined: Fri Jan 09, 2009 4:37 pm
Location: IRAN

### Re: 713 - Adding Reversed Numbers

Why the output is 1998

both of the number is 999
so there reverse will be 999
Code: Select all
` 999 999-----1998`

According to this line.
Code: Select all
`For each case, print exactly one line containing only one integer - the reversed sum of two reversed numbers.`

Now if we reverse the answer then it will be 8991.
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

oh I`m sorry
i solved this problem and i didn`t read that again
try these cases ...

Code: Select all
`23  3and3  23`

Code: Select all
`5326`
Impossible says I`m possible

vahid sanei
Learning poster

Posts: 84
Joined: Fri Jan 09, 2009 4:37 pm
Location: IRAN

### Re: 713 - Adding Reversed Numbers

plz help. Edited bt still WA.
Code: Select all
`removed`
Last edited by Obaida on Wed Jan 21, 2009 8:41 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

why , you dont check the test case of problem ?
try these
Code: Select all
` 24 1 (test case of problem !!!) 1 24 23 44 23`
Impossible says I`m possible

vahid sanei
Learning poster

Posts: 84
Joined: Fri Jan 09, 2009 4:37 pm
Location: IRAN

### Re: 713 - Adding Reversed Numbers

Thank you.
I thought i was passing the sample test cases well.
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 - Runtime error

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;}`

New poster

Posts: 5
Joined: Sun Aug 23, 2009 7:26 am

### Re: 713 - Runtime error

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 ...............
saiful_sust
Learning poster

Posts: 97
Joined: Fri Aug 22, 2008 10:18 pm
Location: CSE.SUST.SYLHET

### Re: 713 - Adding Reversed Numbers

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;}`
aaa111
New poster

Posts: 14
Joined: Sat Nov 21, 2009 2:55 pm

### Re: 713 - Adding Reversed Numbers

Input:
Code: Select all
`2999999 9999991 999999`
Correct output:
Code: Select all
`89999911`
brianfry713
Guru

Posts: 1861
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 713 - Adding Reversed Numbers

Deleted the code after getting AC
Thanks brianfry713
Last edited by mobarak.islam on Sat May 18, 2013 12:17 am, edited 2 times in total.
mobarak.islam
New poster

Posts: 26
Joined: Wed Dec 05, 2012 11:29 pm

### Re: 713 - Adding Reversed Numbers

Input:
Code: Select all
`100265472 2845892749507 152228481114264 4863163436 674450473583771 9375138553 114321594 55519279820686 5045310755 31579928689019 46489469137 66899981653804 51743 574 69719 32801705429895 6830331 8940065761590028 4794013976195 6094977564110832 215000011193 998949171 852023969 808583998867353 669977245 73101257927867 80948240733 71061159623 3539786805551 732454547635 248 606329113207 529428381174967512 36955502 20031041947865 1651045443 188598335 2769952443468316259 14959992 878469946 751343 3421305878548766117 62205166219007 127 348091 95868219189 7866014352950375371 442695 211733266 334946317 683444637939048 699497366 55144587 28105093 224435336512745 110878046 919707522802 787795305564 60873769461563489 16858 96862536828 7117338578387182 9654138768 4975378131 810932573 714139 17533738953 8469824 1776353 774684158 553488636 63624851577 4316309870222 3842977135 8871165951442756 17084866106322 627914864 86607187226235 429 53923418416 9818 64294240788 859115 6990656089959689742 9834349847 7641 5061177396866204 20074604767 6684717 804147614 745902 82789545647 4381693044 688008717 1111006865836 341155 215300095 1840623585601 61217552269 45391412924 4351`
AC output:
Code: Select all
`44006237548298868420364918060467245067644326056927933419662545516417957958170096724804933414711398459895115006579441157822800875856108331920599240210559959864835397601257987185340733459093653829144545476359684863168815967512895860619539656904544336839744486831625976999249469946855560587817081871774190071349503160561143569503753716376666651731393444633934029817326538952443633651274527597982599795305525873769561563489554535899147233518182274411980735454146633713063766943491251582597419463868317893214811659684275662910632256845828268235449225184164600524078665116656089843124733141916117739676940147249285847684286916856479607911448281006868257752380629596076011191469847034`
brianfry713
Guru

Posts: 1861
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 713 - Adding Reversed Numbers

@ 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[i]-48;
j++;
}
for(int i=ln2-1;i>=0;i--)
{
b2[m]=str2[i]-48;
m++;
}
int count=0,chkp=0,aa,bb=0;
for(int i=max-1;i>=0;i--)
{
sum[i]=count+b1[i]+b2[i];

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

if(sum[i]%10==0)
sum[i]=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;
}
mobarak.islam
New poster

Posts: 26
Joined: Wed Dec 05, 2012 11:29 pm

### Re: 713 - Adding Reversed Numbers

Code: Select all
`10018846 293 5396371812887 345499277895 6255126497323 2213885475963 85772199785 5942 76718116 38451162048 5822434918 5514665422870976 7210776261831 8925787442932 89011717124411086 802371 938618487587 2578869331576856 9101806941046735648 2994853264067 122951927375201 7353 48500225 727832499 94171 349627831146486 6594333 1275269811192 1861624225679 287432293997054 959372198499085 8338 59464 90493346498556 779976870991406 1189665714 211 81089519979126 97251257165 101006265141 870201143 578837847 9037609876 7916179774919505334 250279713666472 23831069 821 763375952 921377724 877902277564446156 8868875072776 5205612960407155 429121868 9841029272 2643719910629 53137567956 6386 19835623786 3112420791216 6747919687 102836114368486 569297119691679 667193345204571596 905967056461382 89145 83180582093 4161277 85155418349362 770549360485 686231649284159114 4622986136714042 78 762383461674 2676155738888706 59164651591791 61123971021 85201 607358665246477 495804 25492164096766293954 9384931121 23222393083 14546889797580870209 26791798297477292 362580574304 84263696155604365 87901065553 4419123 15101664694 1749111 121854062 47798562457 4621424 48300822 66997 85917783038 98133656 76485588 282482497110568 925486 463844556`
AC output:
Code: Select all
`379468399726715568421612649754438854517461997811971811989343064484794665422502944726976678742205371715641086658633276297853238280739316988487625329273492019160029778323401411727831125867095698297092424342332925918749225990853055549334646655417950667406924910883440891262267128639430164369147847462505687417977414436408433719733759451377722879022754333561562802989513327155103882927464371945062976566795679835934986579121689370591482877417768859151119449543541482975590582093473235183461774523379159221478084836714042572383461832715578705346676040925702180835865346477735331640951572939546261121368309638991600501195500687925956769692571491119719124510166462592328540667169562457697248887588087830388336568210413180710568840944556`
brianfry713
Guru

Posts: 1861
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

PreviousNext