A15238 | Palindromic Numbers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
During a daily walk Alina noticed a long number written on the ground. Now Alina wants to find some positive number of same length without leading zeroes, such that the sum of these two numbers is a palindrome.
Recall that a number is called a palindrome, if it reads the same right to left and left to right. For example, numbers $121, 66, 98989$ are palindromes, and $103, 239, 1241$ are not palindromes.
Alina understands that a valid number always exist. Help her find one!
Recall that a number is called a palindrome, if it reads the same right to left and left to right. For example, numbers $121, 66, 98989$ are palindromes, and $103, 239, 1241$ are not palindromes.
Alina understands that a valid number always exist. Help her find one!
输入格式
The first line of input data contains an integer $t$ ( $1 \leq t \leq 100$ ) — the number of test cases. Next, descriptions of $t$ test cases follow.
The first line of each test case contains a single integer $n$ ( $2 \leq n \leq 100\,000$ ) — the length of the number that is written on the ground.
The second line of contains the positive $n$ -digit integer without leading zeroes — the number itself.
It is guaranteed that the sum of the values $n$ over all test cases does not exceed $100\,000$ .
The first line of each test case contains a single integer $n$ ( $2 \leq n \leq 100\,000$ ) — the length of the number that is written on the ground.
The second line of contains the positive $n$ -digit integer without leading zeroes — the number itself.
It is guaranteed that the sum of the values $n$ over all test cases does not exceed $100\,000$ .
输出格式
For each of $t$ test cases print an answer — a positive $n$ -digit integer without leading zeros, such that the sum of the input integer and this number is a palindrome.
We can show that at least one number satisfying the constraints exists. If there are multiple solutions, you can output any of them.
We can show that at least one number satisfying the constraints exists. If there are multiple solutions, you can output any of them.
输入输出样例
输入 #1
3 2 99 4 1023 3 385
输出 #1
32 8646 604
In the first test case $99 + 32 = 131$ is a palindrome. Note that another answer is $12$ , because $99 + 12 = 111$ is also a palindrome.
In the second test case $1023 + 8646 = 9669$ .
In the third test case $385 + 604 = 989$ .
In the second test case $1023 + 8646 = 9669$ .
In the third test case $385 + 604 = 989$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted