# JULKA Prob on SPOJ

I was trying to solve the JULKA prob on SPOJ in C++.
The code is working fine on ideone and giving correct results for my test cases too!

But when I submit it, I get WA!
Here is my code:

#include
using namespace std;

int main() {
string s;
while(c–){
cin>>s;
sizex = s.length();
for(i=0;i<sizex;i++)
x[i]=s[i]-‘0’;

``````	cin>>s;
sizey = s.length();
for(i=0;i<sizey;i++)
y[i]=s[i]-'0';
/*	for(i=0;i<sizey;i++)
cout<<y[i];*/
i=0;
j=0;
if(x[0]==1) {
left=1;
i++;
}
else left=0;

for(;i<sizex;i++){
x1[j++]=(left*10+x[i])/2;
left = (left*10+x[i])%2;
}
if(x[0]==1) sizex1=sizex-1;
else sizex1=sizex;
/*for(i=0;i<sizex1;i++)
cout<<x1[i];
cout<<endl;
*/
i=0;
j=0;
if(y[0]==1) {
left=1;
i++;
}
else left=0;
for(;i<sizey;i++){
y1[j++]=(left*10+y[i])/2;
left = (left*10+y[i])%2;
}
if(y[0]==1) sizey1=sizey-1;
else sizey1=sizey;
/*
for(i=0;i<sizey1;i++)

cout<<y1[i];
cout<<endl;
*/
left=0;
j=sizex1;
k=sizex1-1;
for(i=sizey1-1;i>=0;i--){
left = (x1[k]+y1[i]+left)/10;
j--;
k--;
}

for(i=sizex1-sizey1;i>=1;i--){
left = (x1[i-1]+left)/10;
}

if(left!=0) {
}
cout<<endl;
*/
left=0;
j=sizex1-1;
k=sizex1-1;
for(i=sizey1-1;i>=0;i--){
if(x1[k]<y1[i]){
sub[j--]=x1[k--]+10-y1[i];
x1[k]--;
}
else
sub[j--]=x1[k--]-y1[i];
}
for(i=sizex1-sizey1-1;i>=0;i--)
sub[i]=x1[i];
if(sub[0]==0) sizesub=sizex1-1;
else sizesub=sizex1;

if(x[sizex-1]%2==0){
cout<<endl;
}
else {
cout<<endl;
}
if(sizesub>=sizex1){
for(i=0;i<sizesub;i++)
cout<<sub[i];
cout<<endl;
}
else {
for(i=1;i<=sizesub;i++)
cout<<sub[i];
cout<<endl;
}
}

else{

}
}
else {

}
if(left!=0) {
}
else
}

cout<<endl;
}
else {
cout<<endl;
}
if(sizesub>=sizex1){
for(i=0;i<sizesub;i++)
cout<<sub[i];
cout<<endl;
}
else {
for(i=1;i<=sizesub;i++)
cout<<sub[i];
cout<<endl;
}

}

}
return 0;
``````

}

try 100000 80 as a test case. It gives 50040 50-160 as output.There might be some logical error in the code for subtraction due to which -1 is coming as answer.

#include
#include<string.h>
using namespace std;

int main()
{
char num[200],more[200];
int test,ind,div1;

``````for(int i=0;i<10;i++)
{
cin>>num>>more;

ind =-1;
int len1 = strlen(num) - 1;
int len2 = strlen(more) - 1;
for(int j=0;j<=len1;j++)
{
div[j] = num[j] - 48;
}
for(int j=0;j<=len2;j++)
{
sub[j] = more[j] - 48;
}
``````

int k=0,rem=0,b=len2,a=len1;

``````    for(int z=len2;z>=0;z--)
{
if(div[a]<sub[b])
{

div[a] = div[a] - sub[b] + 10;

div[a-1]--;

}
else
{
div[a] = div[a] - sub[b];

}
a--;b--;
}
``````

while(div[a]<0)
{
div[a]+=10;
div[a-1]–;
a–;
}

``````    while(k<=len1)
{
div[k] = div[k] + 10*rem;
if(div[k]==1 && k!=len1)
{
div1 = 10*div[k] + div[++k];
}
else if(div[k]==0)
{
ans[++ind] = 0;
if(k==len1)
break;
else
k++;
continue;
}
else
{
div1=div[k];
}
ans[++ind] = div1/2;
rem=div1%2;
k++;
}
a=ind,b=len2;
int sum,carry=0,index=-1;
while(true)
{
if(a<0 || b<0)
break;
sum = ans[a] + sub[b] + carry;
carry = sum/10;
a--;b--;
}

if(ind>len2)
{
a++;

while(a>0)
{
sum = ans[--a] + carry;
carry = sum/10;
}
}
else if(len2>ind)
{
b++;
while(b>0)
{
sum = sub[--b] + carry;
carry = sum/10;
}
}

while(carry>0)
{
carry = carry/10;
}

{
index--;
}

while(index>=0)
{
index--;
}
cout<<endl;

int x=0;
while(ans[x]==0)
{
x++;
}

while(x<=ind)
{
cout<<ans[x];
x++;
}

cout<<endl;

}

return 0;
``````

}