Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.9 kB
1
Indexable
Never
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
 
#include <bits/stdc++.h>
 
#define fierce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define sz size()

const int N = 2e5+7;
const int E = 1e8+7;
const long long inf = 1e18+7;
 
using namespace std;
 
string BinNumber(int n){
	string s;
	while(n != 1){
		if(n % 2 == 1){
			s += '1';
		}else{
			s += '0';
		} n = n >> 1;
	}
	s += '1';
	reverse(s.begin(), s.end());
	return s;
}

int gcd(int a, int b){
  while(a and b) {
    if(a>b)
      a %= b;
    else
      b %= a;
  }
  return a+b;
}

void init(){
	fierce
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);	
	#endif
}

int a[N], b[N];
int Nr = 1;
int ans, cnt, sum;
int dp[N], pref[N];

signed main(){
    init();
    cin >> Nr; 
    while(Nr--){
    	string s1, s2;
    	cin >> s1 >> s2;
    	string s = "";
    	while(s1.sz != 0 && s2.sz != 0){
    		if(s2[s2.sz - 1] == s1[s1.sz - 1]){
    			s += '0';
    			s1.erase(s1.sz - 1, 1);
    			s2.erase(s2.sz - 1, 1);
    		}else if(s2[s2.sz - 1] < s1[s1.sz - 1]){
    			int num = (s2[s2.sz - 1] - '0');
    			int cl = (num + 10) - (s1[s1.sz - 1] - '0');
      			s += to_string(cl);
      			s1.erase(s1.sz - 1, 1);
    			s2.erase(s2.sz - 2, 2);
    		}else if(s2[s2.sz - 1] > s1[s1.sz - 1]){
    			int num = (s2[s2.sz - 1] - '0') - (s1[s1.sz - 1] - '0');
    			s += to_string(num); 
    			s1.erase(s1.sz - 1, 1);
    			s2.erase(s2.sz - 1, 1);
    		}
    	}
    	s += s2;
    	s2.clear();
    	if(s1.sz != 0 || s2.sz != 0){
    		cout << "-1" << endl;
    	}else{
    	reverse(s.begin(), s.end());
    		cout << s << endl;
    	}
    }
}