欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1834B.Maximum Strength
Maximum Strength
Fedya is playing a new game called "The Legend of Link", in which one of the character's abilities is to combine two materials into one weapon. Each material has its own strength, which can be represented by a positive integer . The strength of the resulting weapon is determined as the sum of the absolute differences of the digits in the decimal representation of the integers at each position.
Formally, let the first material have strength , and the second material have strength . Then the strength of the weapon is calculated as $|x_{1} - y_{1}| + |x_{2} - y_{2}| + \ldots + |x_{n} - y_{n}|$. If the integers have different lengths, then the shorter integer is padded with leading zeros.
Fedya has an unlimited supply of materials with all possible strengths from to , inclusive. Help him find the maximum possible strength of the weapon he can obtain.
An integer is defined as an integer obtained by sequentially writing the digits from left to right, i.e. $10^{k-1} \cdot c_1 + 10^{k-2} \cdot c_2 + \ldots + c_k$.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains two integers and () — the decimal representation of the integers representing the minimum and maximum strength of the materials that Fedya has. It is guaranteed that the integers and do not contain leading zeros.
Note that the input data may not fit into standard -bit or -bit integer data types.
Output
For each test case print one integer — the maximum possible strength of the weapon that Fedya can obtain from the given materials.
Note
In the first test case, the weapon made from materials with strengths and will have the maximum possible strength: .
In the second test case, the maximum strength is achieved with materials with strengths and : .
In the fourth test case, there is only one valid strength, so the answer is .
In the sixth test case, the maximum strength is achieved with materials with strengths and : . Note that the shorter integer was padded with leading zeros.
Samples
6
53 57
179 239
13 37
132228 132228
54943329752812629795 55157581939688863366
88 1914
4
19
11
0
163
28
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |