309745: CF1729B. Decode String

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

Description

Decode String

题意翻译

### 题目大意 Polycarp将一个**全小写**字母的字符串 s 做了以下编码: 1. 如果这个字符在字母表中的编号 ( 如 字符 $'a'$ 的编号为 $1$,字符 $'z'$ 为 $26$ ) 为**个位**数 $(< 10)$,则直接输出其编号; 2. 如果这个字符在字母表中的编号为**两位**数 $(\geqslant 10)$,则在输出他的编号的基础上在其**之后**再输出一个 $0$。 现给出编码后的字符串 $t$ ,请求出他对应的原串。 ### 输入格式 第一行一个整数 $q \; (1 \leqslant q \leqslant 10^4)$ 表示测试样例组数。 对于每组测试样例,第一行一个整数 $n \; (1 \leqslant n \leqslant 50)$ 表示编码后的字符串长度。 第二行包含一个字符串 $t$ 表示编码后的字符串。 ### 输出格式 对于每组测试样例,输出一行一个字符串 $s$ 表示原串 $Translated \; by \; Zigh$

题目描述

Polycarp has a string $ s $ consisting of lowercase Latin letters. He encodes it using the following algorithm. He goes through the letters of the string $ s $ from left to right and for each letter Polycarp considers its number in the alphabet: - if the letter number is single-digit number (less than $ 10 $ ), then just writes it out; - if the letter number is a two-digit number (greater than or equal to $ 10 $ ), then it writes it out and adds the number 0 after. For example, if the string $ s $ is code, then Polycarp will encode this string as follows: - 'c' — is the $ 3 $ -rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); - 'o' — is the $ 15 $ -th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); - 'd' — is the $ 4 $ -th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); - 'e' — is the $ 5 $ -th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045. You are given a string $ t $ resulting from encoding the string $ s $ . Your task is to decode it (get the original string $ s $ by $ t $ ).

输入输出格式

输入格式


The first line of the input contains an integer $ q $ ( $ 1 \le q \le 10^4 $ ) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $ n $ ( $ 1 \le n \le 50 $ ) — the length of the given code. The second line of the description of each test case contains a string $ t $ of length $ n $ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $ t $ is obtained.

输出格式


For each test case output the required string $ s $ — the string that gives string $ t $ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique.

输入输出样例

输入样例 #1

9
6
315045
4
1100
7
1213121
6
120120
18
315045615018035190
7
1111110
7
1111100
5
11111
4
2606

输出样例 #1

code
aj
abacaba
ll
codeforces
aaaak
aaaaj
aaaaa
zf

说明

The first test case is explained above. In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $ 1 $ , so 1 will be appended to the code. The number of the letter j is $ 10 $ , so 100 will be appended to the code. The resulting code is 1100. There are no zeros in the third test case, which means that the numbers of all letters are less than $ 10 $ and are encoded as one digit. The original string is abacaba. In the fourth test case, the string $ s $ is equal to ll. The letter l has the number $ 12 $ and is encoded as 120. So ll is indeed 120120.

Input

题意翻译

### 题目大意 Polycarp将一个**全小写**字母的字符串 s 做了以下编码: 1. 如果这个字符在字母表中的编号 ( 如 字符 $'a'$ 的编号为 $1$,字符 $'z'$ 为 $26$ ) 为**个位**数 $(< 10)$,则直接输出其编号; 2. 如果这个字符在字母表中的编号为**两位**数 $(\geqslant 10)$,则在输出他的编号的基础上在其**之后**再输出一个 $0$。 现给出编码后的字符串 $t$ ,请求出他对应的原串。 ### 输入格式 第一行一个整数 $q \; (1 \leqslant q \leqslant 10^4)$ 表示测试样例组数。 对于每组测试样例,第一行一个整数 $n \; (1 \leqslant n \leqslant 50)$ 表示编码后的字符串长度。 第二行包含一个字符串 $t$ 表示编码后的字符串。 ### 输出格式 对于每组测试样例,输出一行一个字符串 $s$ 表示原串 $Translated \; by \; Zigh$

Output

题目大意:

Polycarp 将一个全小写字母的字符串 s 进行编码:

1. 如果这个字符在字母表中的编号(如字符 'a' 的编号为 1,字符 'z' 为 26)为个位数(< 10),则直接输出其编号;
2. 如果这个字符在字母表中的编号为两位数(≥ 10),则在输出他的编号的基础上在其之后再输出一个 0。

现给出编码后的字符串 t,求出它对应的原串 s。

输入格式:

第一行一个整数 q (1 ≤ q ≤ 10^4) 表示测试样例组数。

对于每组测试样例,第一行一个整数 n (1 ≤ n ≤ 50) 表示编码后的字符串长度。

第二行包含一个字符串 t 表示编码后的字符串。

输出格式:

对于每组测试样例,输出一行一个字符串 s 表示原串。

题目描述:

Polycarp 有一个由小写拉丁字母组成的字符串 s。

他用以下算法对它进行编码:

他逐个查看字符串 s 中的字母,并考虑每个字母在字母表中的编号:

- 如果字母编号是一位数(小于 10),那么直接写出这个数;
- 如果字母编号是两位数(大于或等于 10),那么写出这个数并在其后添加数字 0。

例如,如果字符串 s 是 code,那么 Polycarp 将这样编码这个字符串:

- 'c' 是字母表中的第 3 个字母。因此,Polycarp 在编码中添加 3(编码变为 3);
- 'o' 是字母表中的第 15 个字母。因此,Polycarp 在编码中添加 15 并且再添加一个 0(编码变为 3150);
- 'd' 是字母表中的第 4 个字母。因此,Polycarp 在编码中添加 4(编码变为 31504);
- 'e' 是字母表中的第 5 个字母。因此,Polycarp 在编码中添加 5(编码变为 315045)。

因此,字符串 code 的编码是 315045。

给出一个由字符串 s 编码得到的字符串 t。你的任务是解码它(通过 t 获取原始字符串 s)。

输入输出格式:

输入的第一行包含一个整数 q (1 ≤ q ≤ 10^4) — 输入中测试用例的数量。

接下来是每个测试用例的描述。

每个测试用例的第一行包含一个整数 n (1 ≤ n ≤ 50) — 给定编码的长度。

每个测试用例的第二行包含一个长度为 n 的字符串 t — 给定的编码。保证存在这样一个由小写拉丁字母组成的字符串,编码后得到字符串 t。

输出格式:

对于每个测试用例输出所需的字符串 s — 通过编码得到字符串 t 的字符串。保证这样的字符串总是存在。可以证明这样的字符串总是唯一的。

输入输出样例:

输入样例 #1:

```
9
6
315045
4
1100
7
1213121
6
120120
18
315045615018035190
7
1111110
7
1111100
5
11111
4
2606
```

输出样例 #1:

```
code
aj
abacaba
ll
codeforces
aaaak
aaaaj
aaaaa
zf
```

说明:

第一个测试用例已经在题目描述中解释。

在第二个测试用例中,答案是 aj。实际上,字母 a 的编号是 1,所以 1 会被添加到编码中。字母 j 的编号是 10,所以 100 会被添加到编码中。得到的编码是 1100。

第三个测试用例中没有零,这意味着所有字母的编号都小于 10 并且被编码为一位数字。原始字符串是 abacaba。

在第四个测试用例中,字符串 s 等于 ll。字母 l 的编号是 12,被编码为 120。所以 ll 实际上是 120120。题目大意: Polycarp 将一个全小写字母的字符串 s 进行编码: 1. 如果这个字符在字母表中的编号(如字符 'a' 的编号为 1,字符 'z' 为 26)为个位数(< 10),则直接输出其编号; 2. 如果这个字符在字母表中的编号为两位数(≥ 10),则在输出他的编号的基础上在其之后再输出一个 0。 现给出编码后的字符串 t,求出它对应的原串 s。 输入格式: 第一行一个整数 q (1 ≤ q ≤ 10^4) 表示测试样例组数。 对于每组测试样例,第一行一个整数 n (1 ≤ n ≤ 50) 表示编码后的字符串长度。 第二行包含一个字符串 t 表示编码后的字符串。 输出格式: 对于每组测试样例,输出一行一个字符串 s 表示原串。 题目描述: Polycarp 有一个由小写拉丁字母组成的字符串 s。 他用以下算法对它进行编码: 他逐个查看字符串 s 中的字母,并考虑每个字母在字母表中的编号: - 如果字母编号是一位数(小于 10),那么直接写出这个数; - 如果字母编号是两位数(大于或等于 10),那么写出这个数并在其后添加数字 0。 例如,如果字符串 s 是 code,那么 Polycarp 将这样编码这个字符串: - 'c' 是字母表中的第 3 个字母。因此,Polycarp 在编码中添加 3(编码变为 3); - 'o' 是字母表中的第 15 个字母。因此,Polycarp 在编码中添加 15 并且再添加一个 0(编码变为 3150); - 'd' 是字母表中的第 4 个字母。因此,Polycarp 在编码中添加 4(编码变为 31504); - 'e' 是字母表中的第 5 个字母。因此,Polycarp 在编码中添加 5(编码变为 315045)。 因此,字符串 code 的编码是 315045。 给出一个由字符串 s 编码得到的字符串 t。你的任务是解码它(通过 t 获取原始字符串 s)。 输入输出格式: 输入的第一行包含一个整数 q (1 ≤ q ≤ 10^4) — 输入中测试用例的数量。 接下来是每个测试用例的描述。 每个测试用例的第一行包含一个整数 n (1 ≤ n ≤ 50) — 给定编码的长度。 每个测试用例的第二行包含一个长度为 n 的字符串 t — 给定的编码。保证存在这样一个由小写拉丁字母组成的字符串,编码后得到字符串 t。 输出格式: 对于每个测试用例输出所需的字符串 s — 通过编码得到字符串 t 的字符串。保证这样的字符串总是存在。可以证明这样的字符串总是唯一的。 输入输出样例: 输入样例 #1: ``` 9 6 315045 4 1100 7 1213121 6 120120 18 315045615018035190 7 1111110 7 1111100 5 11111 4 2606 ``` 输出样例 #1: ``` code aj abacaba ll codeforces aaaak aaaaj aaaaa zf ``` 说明: 第一个测试用例已经在题目描述中解释。 在第二个测试用例中,答案是 aj。实际上,字母 a 的编号是 1,所以 1 会被添加到编码中。字母 j 的编号是 10,所以 100 会被添加到编码中。得到的编码是 1100。 第三个测试用例中没有零,这意味着所有字母的编号都小于 10 并且被编码为一位数字。原始字符串是 abacaba。 在第四个测试用例中,字符串 s 等于 ll。字母 l 的编号是 12,被编码为 120。所以 ll 实际上是 120120。

加入题单

算法标签: