#C3218. Generate Unique Item Codes

    ID: 46621 Type: Default 1000ms 256MiB

Generate Unique Item Codes

Generate Unique Item Codes

You are given an integer \(T\) representing the number of test cases. For each test case, you are given an integer \(K\) and an item name (a string that may contain spaces and special characters).

The task is to generate a unique code for the item by processing the name as follows:

  • Traverse the item name character by character.
  • If the character is alphanumeric (i.e. a letter or a digit), include it in the code.
  • If the character is a space, replace it with an underscore (_) and include it.
  • Ignore any other special characters.
  • Take the first \(K\) characters from the processed string. If there are less than \(K\) characters, append the character '#' to the right until the length is exactly \(K\).

For example, given \(K = 5\) and the item name "Open #Box!", the processed string is "Open_" (the space becomes underscore, special characters are removed) and the result is "Open_".

inputFormat

The first line contains an integer \(T\), the number of test cases.

Each test case consists of two lines:

  1. An integer \(K\), representing the required length of the item code.
  2. A string representing the item name, which can contain spaces and special characters.

outputFormat

For each test case, output a single line containing the generated item code.

## sample
4
5
Open #Box!
3
USB-Drive
4
4K TV
7
Notebook
Open_

USB 4K_T Noteboo

</p>