CF1619C.Wrong Addition
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Tanya is learning how to add numbers, but so far she is not doing it correctly. She is adding two numbers a and b using the following algorithm:
- If one of the numbers is shorter than the other, Tanya adds leading zeros so that the numbers are the same length.
- The numbers are processed from right to left (that is, from the least significant digits to the most significant).
- In the first step, she adds the last digit of a to the last digit of b and writes their sum in the answer.
- At each next step, she performs the same operation on each pair of digits in the same place and writes the result to the left side of the answer.
For example, the numbers a=17236 and b=3465 Tanya adds up as follows:
largebeginarrayr+beginarrayr1723603465endarrayhlinebeginarrayr1106911endarrayendarray
- calculates the sum of 6+5=11 and writes 11 in the answer.
- calculates the sum of 3+6=9 and writes the result to the left side of the answer to get 911.
- calculates the sum of 2+4=6 and writes the result to the left side of the answer to get 6911.
- calculates the sum of 7+3=10, and writes the result to the left side of the answer to get 106911.
- calculates the sum of 1+0=1 and writes the result to the left side of the answer and get 1106911.
As a result, she gets 1106911.
You are given two positive integers a and s. Find the number b such that by adding a and b as described above, Tanya will get s. Or determine that no suitable b exists.
塔尼娅正在学习如何做加法,但到目前为止她还做得不对。她使用以下算法将两个数 a 和 b 相加:
- 若其中一个数的位数比另一个少,则塔尼娅在较短的数前面补零,使两数长度相等。
- 从右向左(即从最低位到最高位)依次处理各位数字。
- 第一步,她将 a 的最后一位与 b 的最后一位相加,并将它们的和写入答案中。
- 在后续每一步中,她对同一位上的两个数字执行相同的操作,并将结果写在当前答案的左侧。
例如,塔尼娅将 a=17236 和 b=3465 相加的过程如下:
+17236034651106911
- 计算 6+5=11,并将 11 写入答案;
- 计算 3+6=9,并将结果写在当前答案左侧,得到 911;
- 计算 2+4=6,并将结果写在当前答案左侧,得到 6911;
- 计算 7+3=10,并将结果写在当前答案左侧,得到 106911;
- 计算 1+0=1,并将结果写在当前答案左侧,得到 1106911。
最终结果为 1106911。
现给你两个正整数 a 和 s。请找出一个数 b,使得按上述方式将 a 与 b 相加后,塔尼娅得到的结果恰好为 s;若不存在这样的 b,则判定其不存在。
输入格式
The first line of input data contains an integer t (1≤t≤104) — the number of test cases.
Each test case consists of a single line containing two positive integers a and s (1≤a<s≤1018) separated by a space.
输入数据的第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。
每个测试用例由一行组成,该行包含两个用空格分隔的正整数 a 和 s(1≤a<s≤1018)。
输出格式
For each test case print the answer on a separate line.
If the solution exists, print a single positive integer b. The answer must be written without leading zeros. If multiple answers exist, print any of them.
If no suitable number b exists, output -1.
对每个测试用例,在单独的一行上输出答案。
如果解存在,输出一个正整数 b。答案不得包含前导零。若存在多个答案,输出其中任意一个即可。
若不存在满足条件的数 b,则输出 -1。
输入输出样例
输入#1
6 17236 1106911 1 5 108 112 12345 1023412 1 11 1 20
输出#1
3465 4 -1 90007 10 -1
说明/提示
The first test case is explained in the main part of the statement.
In the third test case, we cannot choose b that satisfies the problem statement.
第一个测试用例在题面主文中已作解释。
在第三个测试用例中,我们无法选择满足题目要求的 b。
输入解题思路,AI测评打分。不知道怎么写?