Orig Description
Kobuta Nuki Kitsuneko
B-boy, a relative of Mrs. A, came to her house. He loves singing and is only 3 years old. He enthusiastically sings a song called "Kobuta Nuki Kitsuneko" (written and composed by Naotoshi Yamamoto) that he learned in kindergarten. In this song, four words, "kobuta," "nuki," "kitsune", and "neko," are played in order, and the last sound and the first sound are the same. B-boy asked A if she could make a similar word chain using words he said.
To help A, let's create a program that determines whether it is possible to make a word chain using all the given words in order and whether the first letter of the first word and the last letter of the last word are the same.
Create a program that takes n words as input and determines whether a word chain can be created from the combination of those words. If it is possible, output OK, and if it is impossible, output NG.
Input
Multiple datasets are given as input. The end of the input is indicated by a single zero line.
Each dataset is given in the following format.
n
word1
word2
:
wordn
The number of words n (2 ≤ n ≤ 10000) is given on the first line. The following n lines contain n words wordi (a string consisting of up to 32 lowercase English letters).
There are no more than 50 datasets.
Output
For each input dataset, output the determination result on one line.
Sample Input
5
apple
yellow
georgia
king
email
7
apple
yellow
georgia
king
email
wink
lucky
0
Output for the Sample Input
NG
OK
Extracted Specification
An integer n (2 ≤ n ≤ 10000), representing some quantity or size.
A list of strings of size n, where each string consists of up to 32 lowercase English letters.
Multiple datasets are given as input. The end of the input is indicated by a single zero line. There are no more than 50 datasets.
### Example Input:
```
5
apple
yellow
georgia
king
email
7
apple
yellow
georgia
king
email
wink
lucky
0
```
### Function Signature:
Write a function f(inputs) that takes in the input.
```python
def f(inputs: List[Tuple[int, List[str]]]):
'''
inputs: a list of tuples, where each tuple contains an integer and a list of strings
'''
```
Test Case Generator
Sure! Let's create a test case generator for the given problem "Kobuta Nuki Kitsuneko".
Here's a Python function to generate random test cases based on the constraints and requirements mentioned in the problem statement:
```python
import random
import string
def generate_word():
# Generate a random word with a length between 1 and 32
length = random.randint(1, 32)
return ''.join(random.choices(string.ascii_lowercase, k=length))
def generate_dataset():
n = random.randint(2, 10000)
words = [generate_word() for _ in range(n)]
return n, words
def tcgen():
datasets = []
for _ in range(50):
n, words = generate_dataset()
datasets.append((n, words))
return datasets
# Generate the test cases
test_cases = tcgen()
# Example usage
for n, words in test_cases:
print(n)
for word in words:
print(word)
print("0") # End of this dataset
```
### Explanation:
1. **`generate_word()`**:
- This function generates a random word with a length between 1 and 32 using lowercase English letters.
2. **`generate_dataset()`**:
- This function generates a single dataset by first picking a random number `n` (the number of words) between 2 and 10000.
- It then generates `n` random words using the `generate_word()` function.
3. **`tcgen()`**:
- This function generates up to 50 datasets as specified in the problem statement.
- Each dataset consists of an integer `n` followed by `n` words.
- The end of each dataset is marked by a `0`, indicating the end of input.
### Example Output:
The output will be in the format:
```
n
word1
word2
:
wordn
0
```
Where each dataset is separated by a `0` indicating the end of the current dataset. The example code prints all datasets, and you can redirect these outputs to a file or use them as required.
Feel free to modify the code to suit your specific needs or constraints!
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) # Just for debugging purposes, to see the extracted arguments