#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char a[100], b[100], c[100];
int i, j, n, m, x, y, r, d, l;
cin >> a >> b;
x = a[0] - 48;
y = b[0] - 48;
strrev(a);
strrev(b);
n = strlen(a);
m = strlen(b);
if((x < y && n == m)|| n < m)
{
cout << "Impossible." << endl;
return 0;
}
i = 0;
r = 0;
while(i<n)
{
x = y = d = 0;
if(i<n)
{
x = a[i] - 48;
x = x - r;
r = 0;
}
if(i<m)
{
y = b[i] - 48;
}
if(x<y)
{
x = x+10;
r = 1;
}
d = x - y;
c[i] = d+48;
i++;
}
c[i] = '\0';
l = strlen(c);
l = l-1;
while(c[l] == '0')
{
c[l] = '\0';
l--;
}
strrev(c);
cout << c << endl << endl;
return 0;
}
#include<cstring>
using namespace std;
int main()
{
char a[100], b[100], c[100];
int i, j, n, m, x, y, r, d, l;
cin >> a >> b;
x = a[0] - 48;
y = b[0] - 48;
strrev(a);
strrev(b);
n = strlen(a);
m = strlen(b);
if((x < y && n == m)|| n < m)
{
cout << "Impossible." << endl;
return 0;
}
i = 0;
r = 0;
while(i<n)
{
x = y = d = 0;
if(i<n)
{
x = a[i] - 48;
x = x - r;
r = 0;
}
if(i<m)
{
y = b[i] - 48;
}
if(x<y)
{
x = x+10;
r = 1;
}
d = x - y;
c[i] = d+48;
i++;
}
c[i] = '\0';
l = strlen(c);
l = l-1;
while(c[l] == '0')
{
c[l] = '\0';
l--;
}
strrev(c);
cout << c << endl << endl;
return 0;
}
Comments
Post a Comment