Failing for one test case

#include
#include
using namespace std;
int main() {
int j=0;
string s1,s2;
cin>>s1;
s2[j]=s1[0];
for(int i=0;i<s1.length()-1;i++)
{
if(int(s1[i])<=int(s1[i+1]))
{
s2[j+1]=s1[i+1]-s1[i]+48;
s2[j+2]=s1[i+1];
j=j+2;
}
else
{
s2[j+1]=45;
s2[j+2]=s1[i]-s1[i+1]+48;
s2[j+3]=s1[i+1];
j=j+3;
}
}
for(int i=0;i<=j;i++)
cout<<s2[i];
return 0;
}

hey @namangarg31 in case when the difference between a[i] and a[i+1] is greater than 10 you would require 3 spaces not 2. There is a better way to solve this question All we need to do is just traverse the whole string and for every two adjacent characters just calculate the ascii among them. We will print the characters and the difference between with characters

Code for the new approach: