Problem p01147 - Generation 2

Orig Description

Decrypting the Princess's Code
A brave and boyish poor princess from a country secretly obtained an ancient document written in Japanese while she was out. The princess who could read Japanese immediately began reading the document. Surprisingly, the document revealed the location of an ancient treasure. However, the location of the treasure was written in code, and it was not easy to understand. So, the princess ordered you, her handmaiden, to help decipher the message.
You investigated day and night and discovered that a shortest secret substring (SSS) plays an important role in decoding. SSS is a string that contains all N given words as substrings and has the smallest possible length. You were given the task of finding SSS from the given N words.
Input
The input consists of multiple datasets. The first line of each dataset contains an integer N (1≤N≤10), which is the number of words in the dataset. The next N lines contain the words. Input containing only a line of 0 indicates the end of the input.
The input words contain only lowercase letters of the alphabet and have a maximum length of 10.
Output
For each dataset, output SSS on one line. If there are multiple SSS, output the one that comes first in dictionary order.
Sample Input
4
apple
length
things
thin
2
icp
cpc
3
zeta
eta
alphabet
2
until
till
0
Sample Output
applengthings
icpc
zetalphabet
untill

Extracted Specification

An integer N (1 ≤ N ≤ 10), representing some quantity.
N lines of strings, each string containing only lowercase letters of the alphabet and having a maximum length of 10.
The input containing only a line of 0 indicates the end of the input.

### Example Input:

```
4
apple
length
things
thin
2
icp
cpc
0
```

### Function Signature:
Write a function f(inputs) that takes in the input.
def f(inputs: List[Tuple[int, List[str]]]):
    '''
    inputs: a list of tuples where each tuple consists of an integer and a list of strings
    '''

Test Case Generator

Certainly! Let's create a test case generator for the problem "Decrypting the Princess's Code". 

First, let’s summarize the key points of the problem:
- The input consists of multiple datasets.
- Each dataset starts with an integer \( N \) (1 ≤ \( N \) ≤ 10), followed by \( N \) words.
- Each word contains only lowercase letters and has a maximum length of 10.
- The input ends with a line containing the number 0.

Here's a Python function to generate test cases for this problem:

```python
import random
import string

def generate_word(max_length=10):
    length = random.randint(1, max_length)
    return ''.join(random.choice(string.ascii_lowercase) for _ in range(length))

def generate_dataset():
    N = random.randint(1, 10)
    words = [generate_word() for _ in range(N)]
    return [str(N)] + words

def tcgen():
    datasets = []
    # Generate a random number of datasets, for example between 1 and 5
    num_datasets = random.randint(1, 5)
    for _ in range(num_datasets):
        dataset = generate_dataset()
        datasets.append('\n'.join(dataset))
    datasets.append('0')  # End of input marker
    return '\n'.join(datasets)

# Example of generating a test case and printing it
print(tcgen())
```

Explanation:
- `generate_word(max_length=10)`: This function generates a random word with a length between 1 and the specified `max_length` (default is 10). The word consists of random lowercase letters.
- `generate_dataset()`: This function generates one dataset. It starts with a random integer \( N \) between 1 and 10, followed by \( N \) random words.
- `tcgen()`: This function generates multiple datasets (between 1 and 5 in this example) and concatenates them into a single string, with each dataset separated by new lines. It finally appends '0' to signify the end of input.

You can modify the range of `num_datasets` or the `max_length` of the words as needed. This generator ensures that the test cases adhere to the constraints provided in the problem statement.

Extract Arguments

def extract_arguments(fh):
    datasets = []
    while True:
        N = int(fh.readline().strip())
        if N == 0:
            break
        words = [fh.readline().strip() for _ in range(N)]
        datasets.append((N, words))
    return datasets

# if __name__ == "__main__":
#     input_path = sys.argv[1]
#     with open(input_path, 'r') as fh: 
#     datasets = extract_arguments(fh)
#     for data in datasets:
#         print(data)