#P16867. [GKS 2021 #H] Silly Substitutions

    ID: 19194 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2021优先队列队列链表Google Kick Start

[GKS 2021 #H] Silly Substitutions

Problem Description

You are given a string SS of length NN which consists of digits 00-99. You do the following operations on the string in the order given.

  1. Find all the substrings 01\mathtt{01} and replace each of them with 2\mathtt{2}.
  2. Find all the substrings 12\mathtt{12} and replace each of them with 3\mathtt{3}.
  3. Find all the substrings 23\mathtt{23} and replace each of them with 4\mathtt{4}.
  4. Find all the substrings 34\mathtt{34} and replace each of them with 5\mathtt{5}.
  5. Find all the substrings 45\mathtt{45} and replace each of them with 6\mathtt{6}.
  6. Find all the substrings 56\mathtt{56} and replace each of them with 7\mathtt{7}.
  7. Find all the substrings 67\mathtt{67} and replace each of them with 8\mathtt{8}.
  8. Find all the substrings 78\mathtt{78} and replace each of them with 9\mathtt{9}.
  9. Find all the substrings 89\mathtt{89} and replace each of them with 0\mathtt{0}.
  10. Find all the substrings 90\mathtt{90} and replace each of them with 1\mathtt{1}.

You repeat this process in the same given order until none of the above operations change the string. For example, if SS is 12\mathtt{12} then we do not stop at operation 11 since it does not affect the string but perform operation 22 and change the string to 3\mathtt{3}. We can see that the string does not change further no matter how many times we repeat the above process.

Your task is to find how the final string will look like for the given SS.

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case consists of two lines.

The first line of each test case contains an integer NN, denoting the length of the string SS.

The second line of each test case contains a string SS of length NN.

Output Format

For each test case, output one line containing Case #xx: yy, where xx is the test case number (starting from 11) and yy is the final string obtained.

4
3
012
4
0145
5
00000
11
98765432101
Case #1: 22
Case #2: 26
Case #3: 00000
Case #4: 1

Hint

In Sample Case #11, substring 0101 is replaced with 22 and the resulting string is 2222 which is not affected further by any of the operations. Therefore final string is 2222.

In Sample Case #22, substring 0101 is replaced with 22 and the resulting string is 245245. The substring 4545 is replaced with 66 and the resulting string is 2626 which is not further affected by any of the operations. Therefore final string is 2626.

In Sample Case #33, since the operations cannot be performed on the given string, the string does not change.

In Sample Case #44, all the operations can be performed sequentially on the string and the final string is 11.

Limits

1T1001 \le T \le 100.

The input string only consists of digits 00-99.

Test Set 11

1N1001 \le N \le 100.

Test Set 22

For at most 1010 cases:

1N5×1051 \le N \le 5 \times 10^5.

For the remaining cases:

1N1001 \le N \le 100.