• B. Decode String


    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

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

    Input

    The first line of the input contains an integer qq (1≤q≤1041≤q≤104) — 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≤n≤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.

    Output

    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.

    Example

    input

    Copy

     
    

    9

    6

    315045

    4

    1100

    7

    1213121

    6

    120120

    18

    315045615018035190

    7

    1111110

    7

    1111100

    5

    11111

    4

    2606

    output

    Copy

    code
    aj
    abacaba
    ll
    codeforces
    aaaak
    aaaaj
    aaaaa
    zf
    

    Note

    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.

    解题说明:此题是一道模拟题,按照题目需求,序号小于10的字母可以直接通过换算得到,序号大于10的字母需要通过两个数字外加后面的0来确定。遍历判断查找。

    1. #include
    2. #include
    3. int main()
    4. {
    5. int q;
    6. scanf("%d", &q);
    7. while (q--)
    8. {
    9. int n, i, j;
    10. scanf("%d", &n);
    11. char s[51], b[51];
    12. scanf("%s", &s);
    13. for (i = 0, j = 0; i
    14. {
    15. if (s[i + 2] == '0' && s[i + 3] != '0' && i < (n - 1))
    16. {
    17. b[j] = 96 + ((s[i] - 48) * 10) + (s[i + 1] - 48);
    18. i = i + 3;
    19. j++;
    20. }
    21. else
    22. {
    23. b[j] = 96 + (s[i] - 48);
    24. i++;
    25. j++;
    26. }
    27. }
    28. b[j] = '\0';
    29. printf("%s\n", b);
    30. }
    31. return 0;
    32. }

  • 相关阅读:
    空城机在CSDN的四周年创作纪念日
    巴斯光年python turtle绘图__附源代码
    探索 C++20 的新领域:深入理解 static关键字和核心语言特性测试宏
    SpringBoot终幕——日志的输出以及Lombok常用注解
    Java并发之AQS整理:为什么要使用AQS、AQS核心代码流程
    Node编写用户注册接口
    jupyter notebook内核启动报错:ImportError: DLL load failed while importing _device
    顺序表的实现及操作【C语言最详细版】
    10款自媒体人必备的免费工具,快速高效运营
    java毕业设计家政管理系统(附源码、数据库)
  • 原文地址:https://blog.csdn.net/jj12345jj198999/article/details/127136822