Orig Description
The Chair on Which Difficult People Sit
In the neutral city of Aizu in the center of four countries, there is a platform for the transcontinental train Bandai-go. Rows of chairs for passengers waiting for the Bandai-go are provided on the platform, and anyone who enters the platform can use the chairs freely.
The Bandai-go is cheap, fast, and comfortable, so it is always crowded with users from the surrounding four countries. Today is the opening day, and I'm thinking of doing something special for the people sitting on the platform. For this purpose, we need to know where the people who passed through the gate are sitting. Taking into account the difficult personalities of the people from the four countries, please create a program that simulates how the chairs are filled. The people who passed through the gate sit in a row on the chairs one after another. The people from the four countries have decided personality and seating arrangements for each country. The seating arrangements are as follows for each person.
Personality of Person from Country A
A person from country A just wants to sit. They look at the empty chairs from the left end and sit on the first available chair.
Personality of Person from Country B
People from country B do not like people from country A. They sit in the empty chair from the right end, except next to people from country A. However, if there is no other choice than to sit next to someone from country A, they will endure it and sit in the empty chair from the left end.
Personality of Person from Country C
People from country C want to sit next to someone. They look at the person sitting from the left and try to sit next to the person sitting on the far left. However, if that seat is taken, they will try to sit next to the person on the left. If that seat is also taken, they will try to sit next to the next person with the same condition. If no chair is taken, they will sit in the middle (if the number of chairs is odd, it is the center chair ((n+1)/2), and if it is even, it is the chair in the middle of n/2+1).
Personality of Person from Country D
People from country D do not want to sit next to anyone. They try to sit in the chair where the distance from the nearest person is the farthest. If there are multiple seats with the same condition or if they have no choice but to sit next to someone, they will sit in the leftmost chair among those. If no one is sitting in the chair, they will sit in the leftmost chair.
Input the information of the passengers who are trying to get on the Bandai-go, and create a program that outputs how they are sitting on the chairs. The nationality of the person sitting from the left is output. However, if the seat is empty, please output "#" (hash) instead.
Input
Multiple sets of data sets are given as input. The end of the input is indicated by two consecutive zeros.
Each data set is given in the following format.
n m
a1
a2
:
am
The number of chairs n (1 ≤ n ≤ 100) and the number of passengers m (m ≤ n) are given on the first line. The following m lines give the information of the i-th person, ai, in one character. 'A' represents a person from country
Extracted Specification
An integer n (1 ≤ n ≤ 100), representing some quantity or size.
An integer m (m ≤ n), representing another quantity or size.
A list of m characters, where each character is from the set {'A', 'B', 'C', 'D'}.
### Example Input:
```
5 3
A
B
C
```
### Function Signature:
Write a function f(n, m, chars) that takes in the input.
def f(n: int, m: int, chars: List[str]):
'''
n: an integer
m: an integer
chars: a list of characters
'''
Test Case Generator
To generate test cases for the problem "The Chair on Which Difficult People Sit," we will need to ensure the generated cases adhere to the constraints and the behavior described in the problem statement. Here is a Python script to generate such test cases:
```python
import random
def generate_test_case():
# Number of chairs (n) and number of passengers (m)
n = random.randint(1, 100)
m = random.randint(1, n)
# Nationalities of people sitting
nationalities = ['A', 'B', 'C', 'D']
people = [random.choice(nationalities) for _ in range(m)]
return n, m, people
def tcgen():
test_cases = []
# Generate a random number of test cases
num_test_cases = random.randint(1, 10)
for _ in range(num_test_cases):
n, m, people = generate_test_case()
test_cases.append((n, m, people))
# Indicate the end of input
test_cases.append((0, 0, []))
return test_cases
def format_test_cases(test_cases):
formatted_cases = []
for n, m, people in test_cases:
case = f"{n} {m}\n"
case += "\n".join(people)
formatted_cases.append(case)
return "\n".join(formatted_cases)
if __name__ == "__main__":
test_cases = tcgen()
formatted_test_cases = format_test_cases(test_cases)
print(formatted_test_cases)
```
### Explanation
1. **generate_test_case()**: This function generates a single test case.
- Randomly selects the number of chairs (`n`) between 1 and 100.
- Randomly selects the number of passengers (`m`) such that `m <= n`.
- Generates a list of passengers' nationalities, randomly chosen from ['A', 'B', 'C', 'D'].
2. **tcgen()**: This function uses `generate_test_case()` to create a list of test cases.
- Generates a random number of test cases between 1 and 10.
- Appends (0, 0, []) at the end to indicate the end of input as specified.
3. **format_test_cases()**: This function formats the test cases into the required input format.
- Joins the number of chairs and passengers with the nationalities list.
4. **main block**: Generates and prints formatted test cases.
With the above code, you can generate multiple test cases that can be used for the problem "The Chair on Which Difficult People Sit," ensuring a variety of input scenarios for thorough testing.
Extract Arguments
def extract_arguments(fh):
inputs = []
while True:
n, m = map(int, fh.readline().strip().split())
if n == 0 and m == 0:
break
passengers = [fh.readline().strip() for _ in range(m)]
inputs.append((n, m, passengers))
return inputs