CF1729B.Decode String

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Polycarp has a string ss consisting of lowercase Latin letters.

He encodes it using the following algorithm.

He goes through the letters of the string ss 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 1010), then just writes it out;
  • if the letter number is a two-digit number (greater than or equal to 1010), then it writes it out and adds the number 0 after.

For example, if the string ss is code, then Polycarp will encode this string as follows:

  • 'c' — is the 33-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3);
  • 'o' — is the 1515-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150);
  • 'd' — is the 44-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504);
  • 'e' — is the 55-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 tt resulting from encoding the string ss. Your task is to decode it (get the original string ss by tt).

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

他使用以下算法对字符串进行编码:

他从左到右遍历字符串 ss 中的每个字母,并对每个字母,考虑其在字母表中的序号(即 'a' 为第 11 个,'b' 为第 22 个,……,'z' 为第 2626 个):

  • 若该字母的序号为一位数(小于 1010),则直接将其写入编码结果;
  • 若该字母的序号为两位数(大于等于 1010),则将其写入编码结果,并在其后额外添加一个数字 00。

例如,若字符串 ss 为 code,则 Polycarp 将按如下方式对该字符串进行编码:

  • 'c' 是字母表中第 33 个字母,因此 Polycarp 将 3 加入编码结果(此时编码结果为 3);
  • 'o' 是字母表中第 1515 个字母,因此 Polycarp 将 15 加入编码结果,并在其后添加 0(此时编码结果为 3150);
  • 'd' 是字母表中第 44 个字母,因此 Polycarp 将 4 加入编码结果(此时编码结果为 31504);
  • 'e' 是字母表中第 55 个字母,因此 Polycarp 将 5 加入编码结果(此时编码结果为 315045)。

因此,字符串 code 的编码结果为 315045。

现给你一个由字符串 ss 编码所得的字符串 tt。你的任务是将 tt 解码(即根据 tt 还原出原始字符串 ss)。

输入格式

The first line of the input contains an integer qq (1≤q≤1041 \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 nn (1≤n≤501 \le n \le 50) — the length of the given code.

The second line of the description of each test case contains a string tt of length nn — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string tt is obtained.

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

随后是各测试用例的描述。

每个测试用例的描述第一行包含一个整数 nn(1≤n≤501 \le n \le 50)—— 表示给定编码串的长度。

每个测试用例的描述第二行包含一个长度为 nn 的字符串 tt —— 即给定的编码串。题目保证存在某个由小写拉丁字母组成的字符串,其经过编码后恰好得到字符串 tt。

输出格式

For each test case output the required string ss — the string that gives string tt 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.

对于每个测试用例,输出所需的字符串 ss —— 即经过编码后得到字符串 tt 的字符串。保证这样的字符串总是存在,且可以证明该字符串总是唯一的。

输入输出样例

  • 输入#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 11, so 1 will be appended to the code. The number of the letter j is 1010, 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 1010 and are encoded as one digit. The original string is abacaba.

In the fourth test case, the string ss is equal to ll. The letter l has the number 1212 and is encoded as 120. So ll is indeed 120120.

第一个测试用例已在上文解释。

在第二个测试用例中,答案是 aj。事实上,字母 a 的编号为 11,因此将 1 追加到编码中;字母 j 的编号为 1010,因此将 100 追加到编码中。最终得到的编码为 1100。

第三个测试用例中不含数字 0,这意味着所有字母的编号均小于 1010,且均以一位数字编码。原始字符串为 abacaba。

在第四个测试用例中,字符串 ss 等于 ll。字母 l 的编号为 1212,编码为 120。因此 ll 确实编码为 120120。

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

首页