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 n tuples, where each tuple 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, cards) that takes in the input.
```python
def f(n: int, cards: List[Tuple[str, int]]):
'''
n: an integer
cards: a list of tuples, where each tuple contains a character and an integer
'''
```
Test Case Generator
Certainly! Here's a test case generator for the Quick Sort problem described:
### Test Case Generator for Quick Sort
```python
import random
def generate_card():
# Generate a random card suit
suit = random.choice(['S', 'H', 'C', 'D'])
# Generate a random card number
number = random.randint(1, 10**9)
return suit, number
def tcgen(num_cases=1):
test_cases = []
for _ in range(num_cases):
# Generate a random number of cards
n = random.randint(1, 100000)
cards = set()
while len(cards) < n:
card = generate_card()
cards.add(card)
test_case = [f"{n}"]
for suit, number in cards:
test_case.append(f"{suit} {number}")
test_cases.append("\n".join(test_case))
return test_cases
# Usage example
if __name__ == "__main__":
num_cases = 2 # Number of test cases to generate
cases = tcgen(num_cases)
for i, case in enumerate(cases):
print(f"Test Case {i + 1}:\n{case}\n")
```
### Explanation
1. **generate_card()**: This function generates a random card by selecting a random suit from `['S', 'H', 'C', 'D']` and a random number between `1` and `10^9`.
2. **tcgen(num_cases=1)**: This function generates the specified number of test cases (`num_cases`). For each test case:
- It generates a random number `n` of cards.
- It uses a set to ensure that there are no identical cards in the input, as per the problem constraints.
- It constructs the test case in the required format.
### Usage
You can specify the number of test cases you want to generate using the `num_cases` parameter when calling the `tcgen` function. The generated test cases are printed in the specified format.
### Example Output
```
Test Case 1:
6
S 123456789
H 987654321
C 12345678
D 87654321
H 23456789
S 8765432
Test Case 2:
3
S 7654321
D 56789012
C 67890123
```
This generated output can be used for testing your quicksort implementation. Each test case is printed separately, and each card is represented by a suit and a number, ensuring that there are no duplicate cards.
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