Strings-Difference in Ascii Codes question

i am getting wrong ans on 4th testcase.
here is my code.

/******************************************

  • AUTHOR : MD AKDAS AHMAD *
  • YEAR : 2nd *
  • INSTITUTION : JMI *
    ******************************************/
    #include <bits/stdc++.h>
    using namespace std;
    #define LL long long
    #define N 100005
    #define MOD 1000000007
    #define dd double
    #define rep(i, n) for(int i = 0; i < n; i++)
    #define REP(i,a,b) for(int i=a;i<b;i++)
    #define rep1(i,b) for(int i=1;i<=b;i++)
    #define pb push_back
    #define mp make_pair

const int inf=(int)1e9;

int main()
{
string s,t;
//freopen(“input.txt”, “r”, stdin);
//freopen(“output.txt”, “w”, stdout);
getline(cin,s);
int l=s.length();

for(int i=0;i<l;i++)
{ 
    t.push_back(s[i]);

    if(i==l-1)
        cout<<t<<endl;

    else
    { int val=(s[i+1]-'0')-(s[i]-'0');
       if(val<0)
       { t.push_back('-');
          val=-val;
          t.push_back(val+'0');

       }
       else
       	t.push_back(val+'0');
      
    }
 }

return 0;
}

Hi @Akdas
Your code is showing wrong ans for the case when difference is greater than 9 because when you try to push it into the string then a different character is pushed into the string. For example when input is aza then your code is print aIz-Ia but the correct output is a25z-25a. So to correct it you should take each digit of val and then push it into the string.

Here is your corrected code :