Orig Description
Quick Sort
Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode:
Partition(A, p, r)
1 x = A[r]
2 i = p-1
3 for j = p to r-1
4 do if A[j] <= x
5 then i = i+1
6 exchange A[i] and A[j]
7 exchange A[i+1] and A[r]
8 return i+1
Quicksort(A, p, r)
1 if p < r
2 then q = Partition(A, p, r)
3 run Quicksort(A, p, q-1)
4 run Quicksort(A, q+1, r)
Here, A is an array which represents a deck of cards and comparison operations are performed based on the numbers.
Your program should also report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
Input
The first line contains an integer n, the number of cards.
n cards are given in the following lines. Each card is given in a line and represented by a pair of a character and an integer separated by a single space.
Output
In the first line, print the stability ("Stable" or "Not stable") of this output.
In the following lines, print the arranged cards in the same manner of that of the input.
Constraints
1 ≤ n ≤ 100,000
1 ≤ the number of a card ≤ 109
There are no identical card in the input
Sample Input 1
6
D 3
H 2
D 1
S 3
D 2
C 1
Sample Output 1
Not stable
D 1
C 1
D 2
H 2
D 3
S 3
Sample Input 2
2
S 1
H 1
Sample Output 2
Stable
S 1
H 1
Extracted Specification
An integer n (1 ≤ n ≤ 100,000), representing some quantity or size.
A list of pairs where each pair consists of a character from the set {'S', 'H', 'C', 'D'} and an integer (1 ≤ integer ≤ 10^9).
### Example Input:
```
6
D 3
H 2
D 1
S 3
D 2
C 1
```
### Function Signature:
Write a function f(n, inputs) that takes in the input.
```python
def f(n: int, inputs: List[Tuple[str, int]]):
'''
n: an integer
inputs: a list of tuples, each containing a character and an integer
'''
```
Test Case Generator
Sure, let's write a test case generator for the "Quick Sort" problem. The generator will create random test cases based on the given constraints.
Here’s the Python function to generate the test cases:
```python
import random
def generate_card():
"""Generate a random card represented by a suit and a number."""
suit = random.choice(['S', 'H', 'C', 'D'])
number = random.randint(1, 10**9)
return f"{suit} {number}"
def tcgen():
"""Generate a random test case for the Quick Sort problem."""
n = random.randint(1, 100000)
cards = set()
while len(cards) < n:
cards.add(generate_card())
return n, list(cards)
# Function to format the test case as a string
def format_test_case(n, cards):
result = [str(n)]
result.extend(cards)
return "\n".join(result)
# Generate a test case
n, cards = tcgen()
test_case = format_test_case(n, cards)
print(test_case)
```
### Explanation:
1. **generate_card():**
- This function generates a single card consisting of a random suit ('S', 'H', 'C', 'D') and a random number between 1 and \(10^9\).
2. **tcgen():**
- This function generates a random number \(n\) between 1 and 100,000.
- It creates a set of unique cards by repeatedly calling `generate_card()` until the set size reaches \(n\). This ensures all cards are unique as specified in the problem constraints.
3. **format_test_case():**
- This function formats the generated number of cards and the list of cards into the required input format for the problem statement.
### Example Output:
The output would be a string that can be directly used as input for the problem:
```
6
D 123456789
H 987654321
C 123456789
S 987654321
D 111111111
C 222222222
```
This string represents the input format expected by the problem statement, with the first line being the number of cards and each subsequent line representing a card with its suit and number.
Feel free to integrate this generator into your testing framework or modify it as needed for your specific requirements.
Extract Arguments
def extract_arguments(fh):
n = int(fh.readline().strip())
cards = []
for _ in range(n):
suit, number = fh.readline().strip().split()
cards.append((suit, int(number)))
return n, cards