Tried my first real codeforces round, got stuck way too long on one of the earlier questions, but over all, you gotta start somewhere i guess
This commit is contained in:
72
codeforces/rounds/762/c.cpp
Normal file
72
codeforces/rounds/762/c.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef long long ll;
|
||||
|
||||
int first_digit(ll& n){
|
||||
int digits = (int)log10(n);
|
||||
|
||||
n = (int)(n / pow(10, digits));
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void test_case(int tc){
|
||||
ll a, s;
|
||||
cin >> a >> s;
|
||||
|
||||
ll b = 0;
|
||||
int bpow = 0;
|
||||
|
||||
while(a > 0){
|
||||
if(s == 0){
|
||||
cout << -1 << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
int la = a % 10, ls = s % 10;
|
||||
if(ls < la){
|
||||
ls = s % 100;
|
||||
s /= 10;
|
||||
}
|
||||
|
||||
if(ls - la > 9 || la > ls){
|
||||
cout << -1 << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
a /= 10;
|
||||
s /= 10;
|
||||
|
||||
b += (ll)pow(10, bpow) * (ls - la);
|
||||
bpow++;
|
||||
}
|
||||
|
||||
while(s > 0){
|
||||
b += (ll)pow(10, bpow) * (s % 10);
|
||||
s /= 10;
|
||||
bpow++;
|
||||
}
|
||||
|
||||
cout << b << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(){
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
|
||||
for(int tc = 1; tc <= t; ++tc){
|
||||
test_case(tc);
|
||||
}
|
||||
|
||||
cout << flush;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user