CF1700B.Palindromic Numbers

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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,98989121, 66, 98989 are palindromes, and 103,239,1241103, 239, 1241 are not palindromes.

Alina understands that a valid number always exist. Help her find one!

阿尔伊娜在日常散步时注意到地上写了一个很长的数字。现在,阿尔伊娜想找到一个正整数,其位数与该数字相同且不以 0 开头,使得这两个数之和是一个回文数。

回忆一下:若一个数从左到右读与从右到左读完全相同,则称其为回文数。例如,121121、6666、9898998989 是回文数,而 103103、239239、12411241 不是回文数。

阿尔伊娜知道,满足条件的数一定存在。请帮她找出一个!

输入格式

The first line of input data contains an integer tt (1≤t≤1001 \leq t \leq 100) — the number of test cases. Next, descriptions of tt test cases follow.

The first line of each test case contains a single integer nn (2≤n≤100 0002 \leq n \leq 100\,000) — the length of the number that is written on the ground.

The second line of contains the positive nn-digit integer without leading zeroes — the number itself.

It is guaranteed that the sum of the values nn over all test cases does not exceed 100 000100\,000.

输入数据的第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100),表示测试用例的数量。接下来是 tt 个测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤100 0002 \leq n \leq 100\,000),表示写在地面上的数字的长度。

每个测试用例的第二行包含一个 nn 位正整数(无前导零),即该数字本身。

保证所有测试用例的 nn 值之和不超过 100 000100\,000。

输出格式

For each of tt test cases print an answer — a positive nn-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.

对于 tt 个测试用例中的每一个,输出一个答案——一个不含前导零的正 nn 位整数,使得该整数与输入整数之和为回文数。

可以证明,至少存在一个满足约束条件的数。若存在多个解,输出其中任意一个即可。

输入输出样例

  • 输入#1

    3
    2
    99
    4
    1023
    3
    385

    输出#1

    32
    8646
    604

说明/提示

In the first test case 99+32=13199 + 32 = 131 is a palindrome. Note that another answer is 1212, because 99+12=11199 + 12 = 111 is also a palindrome.

In the second test case 1023+8646=96691023 + 8646 = 9669.

In the third test case 385+604=989385 + 604 = 989.

在第一个测试用例中,99+32=13199 + 32 = 131 是一个回文数。注意,另一个答案是 1212,因为 99+12=11199 + 12 = 111 也是一个回文数。

在第二个测试用例中,1023+8646=96691023 + 8646 = 9669。

在第三个测试用例中,385+604=989385 + 604 = 989。

输入解题思路,AI测评打分。不知道怎么写?

首页