Problem p00124 - Generation 3

Orig Description

League Standings Score Sheet
There are league and tournament games in sports. In soccer leagues, points are awarded for wins, losses, and draws, and rankings are determined by those points. The points awarded for each are as follows: win (3 points), loss (0 points), and draw (1 point).
Create a program that inputs the number of teams and their league record, sorts them in order of good performance (based on the number of points) and outputs the team name and points. In case of a tie in points, output in the order of input.
Input
Multiple data sets will be given. Each data set will be in the following format:
n
name1 w1 l1 d1
name2 w2 l2 d2
:
namen wn ln dn
The number of teams, n (n ≤ 10), is given on the first line. On the following n lines, the name namei of team i (up to 20 alphabets), the number of wins wi, the number of losses li, and the number of draws di (0 ≤ wi, li, di ≤ 9) are given, separated by spaces.
When the number of teams is 0, the input is terminated. The number of data sets will not exceed 50.
Output
For each data set, output a list of the sorted teams. On the i-th line, output the name and points of the i-th team separated by a comma.
Insert one blank line between data sets.
Sample Input
4
Japan 1 0 2
Egypt 1 2 0
Canada 0 2 1
Spain 2 0 1
3
India 0 2 0
Poland 1 0 1
Italy 1 0 1
0
Output for the Sample Input
Spain,7
Japan,5
Egypt,3
Canada,1
Poland,4
Italy,4
India,0

Extracted Specification

An integer n (n ≤ 10), representing some quantity or size.  
A list of tuples (name, w, l, d) of size n, where each tuple consists of:  
- name: a string of up to 20 alphabets  
- w: an integer (0 ≤ w ≤ 9)  
- l: an integer (0 ≤ l ≤ 9)  
- d: an integer (0 ≤ d ≤ 9)  

The input terminates when n is 0. Multiple data sets are provided. The number of data sets will not exceed 50.

### Example Input:

```
4
Japan 1 0 2
Egypt 1 2 0
Canada 0 2 1
Spain 2 0 1
3
India 0 2 0
Poland 1 0 1
Italy 1 0 1
0
```

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

Test Case Generator

Here's a test case generator for the "League Standings Score Sheet" problem. This generator will create multiple data sets as specified, ensuring each data set adheres to the input constraints:

```python
import random
import string

def generate_team_name():
    # Generate a random team name with up to 20 alphabetic characters
    length = random.randint(1, 20)
    return ''.join(random.choices(string.ascii_uppercase, k=length))

def generate_team_record():
    # Generate random wins, losses, and draws (0 ≤ wi, li, di ≤ 9)
    wins = random.randint(0, 9)
    losses = random.randint(0, 9)
    draws = random.randint(0, 9)
    return wins, losses, draws

def generate_data_set():
    # Generate a single data set
    n = random.randint(1, 10)
    data_set = []
    for _ in range(n):
        name = generate_team_name()
        wins, losses, draws = generate_team_record()
        data_set.append(f"{name} {wins} {losses} {draws}")
    return n, data_set

def tcgen():
    num_data_sets = random.randint(1, 50)
    test_cases = []
    
    for _ in range(num_data_sets):
        n, data_set = generate_data_set()
        test_cases.append(f"{n}\n" + "\n".join(data_set))
    
    test_cases.append("0")  # Termination line
    
    return "\n\n".join(test_cases)

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

This script generates random test cases for the given problem. Here's a breakdown of what each part does:

- `generate_team_name()`: Generates a random team name of up to 20 characters.
- `generate_team_record()`: Generates random values for wins, losses, and draws, each between 0 and 9, inclusive.
- `generate_data_set()`: Combines the team name and record generation to create a single dataset, including the number of teams.
- `tcgen()`: Generates multiple datasets (up to 50) and formats them as specified in the problem statement. Each dataset is separated by a blank line, and the input is terminated with a "0".

Extract Arguments

def extract_arguments(fh):
    inputs = []
    while True:
        n = int(fh.readline().strip())
        if n == 0:
            break
        teams = []
        for _ in range(n):
            line = fh.readline().strip().split()
            name = line[0]
            w, l, d = map(int, line[1:])
            teams.append((name, w, l, d))
        inputs.append(teams)
    return inputs