309567: CF1700B. Palindromic Numbers

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Palindromic Numbers

题意翻译

#### 题目大意 每天散步时,艾琳娜都会注意到地上有一个很长的数字(一个 $n$ 位数)。现在艾琳娜想找一个不含前导 $0$ 的 $n$ 位数,使得这两个 $n$ 位数的和是一个回文数。 数据保证一定有一个 $n$ 位数符合要求。如果有多个 $n$ 位数符合要求,任意输出其中的一个即可。 (回文数:如果一个数字从右往左读和从左往右读得到的数相同,那么它就被称为回文数。例如,数字121、66、98989是回文数,103、239、1241不是回文数。) #### 输入格式 第一行包含一个整数 $t$($1 \leq t \leq 100$),表示数据组数。 每组数据的第一行包含一个整数 $n$($1 \leq n \leq 10^5$,且保证 $\sum \limits{n} \leq 10^5$),表示地上这个数字的长度为 $n$ 位。第二行包含一个 $n$ 位数,表示地上这个数字本身。 #### 输出格式 对于每组数据,输出一个 $n$ 位数,表示一个符合要求的 $n$ 位数。

题目描述

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!

输入输出格式

输入格式


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 $ .

输出格式


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.

输入输出样例

输入样例 #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 $ .

Input

题意翻译

#### 题目大意 每天散步时,艾琳娜都会注意到地上有一个很长的数字(一个 $n$ 位数)。现在艾琳娜想找一个不含前导 $0$ 的 $n$ 位数,使得这两个 $n$ 位数的和是一个回文数。 数据保证一定有一个 $n$ 位数符合要求。如果有多个 $n$ 位数符合要求,任意输出其中的一个即可。 (回文数:如果一个数字从右往左读和从左往右读得到的数相同,那么它就被称为回文数。例如,数字121、66、98989是回文数,103、239、1241不是回文数。) #### 输入格式 第一行包含一个整数 $t$($1 \leq t \leq 100$),表示数据组数。 每组数据的第一行包含一个整数 $n$($1 \leq n \leq 10^5$,且保证 $\sum \limits{n} \leq 10^5$),表示地上这个数字的长度为 $n$ 位。第二行包含一个 $n$ 位数,表示地上这个数字本身。 #### 输出格式 对于每组数据,输出一个 $n$ 位数,表示一个符合要求的 $n$ 位数。

Output

**回文数**

#### 题目大意

艾琳娜在散步时发现地上有一个n位数,她想要找到一个不含前导0的n位数,使得这两个数的和是一个回文数。保证至少存在一个这样的n位数,如果有多个,输出其中一个即可。

(回文数:一个数字从左到右和从右到左读都相同的数。例如,121、66、98989是回文数,而103、239、1241不是。)

#### 输入格式

第一行包含一个整数t(1≤t≤100),表示数据组数。

每组数据的第一行包含一个整数n(1≤n≤10^5,且所有n之和不超过10^5),表示地上数字的长度。第二行包含一个n位数,表示地上的数字。

#### 输出格式

对于每组数据,输出一个n位数,表示一个符合要求的n位数。

#### 输入输出样例

**输入样例 #1**

```
3
2
99
4
1023
3
385
```

**输出样例 #1**

```
32
8646
604
```

**说明**

第一个测试案例中,99+32=131是一个回文数。注意,12也是一个有效答案,因为99+12=111也是一个回文数。

第二个测试案例中,1023+8646=9669。

第三个测试案例中,385+604=989。**回文数** #### 题目大意 艾琳娜在散步时发现地上有一个n位数,她想要找到一个不含前导0的n位数,使得这两个数的和是一个回文数。保证至少存在一个这样的n位数,如果有多个,输出其中一个即可。 (回文数:一个数字从左到右和从右到左读都相同的数。例如,121、66、98989是回文数,而103、239、1241不是。) #### 输入格式 第一行包含一个整数t(1≤t≤100),表示数据组数。 每组数据的第一行包含一个整数n(1≤n≤10^5,且所有n之和不超过10^5),表示地上数字的长度。第二行包含一个n位数,表示地上的数字。 #### 输出格式 对于每组数据,输出一个n位数,表示一个符合要求的n位数。 #### 输入输出样例 **输入样例 #1** ``` 3 2 99 4 1023 3 385 ``` **输出样例 #1** ``` 32 8646 604 ``` **说明** 第一个测试案例中,99+32=131是一个回文数。注意,12也是一个有效答案,因为99+12=111也是一个回文数。 第二个测试案例中,1023+8646=9669。 第三个测试案例中,385+604=989。

加入题单

算法标签: