Level 1 - Cơ Bản / Basics

Bài Tập 1: Nhân Đôi Phần Tử (Double Each Element)

Đề bài: Nhập một dãy số nguyên. In ra danh sách mới với mỗi phần tử được nhân đôi, trên cùng một dòng cách nhau bởi dấu cách.

Problem: Enter a list of integers. Print a new list with each element doubled, on one line separated by spaces.

Ví dụ:

Enter numbers: 3 5 2 8

Output:

6 10 4 16

Bài Tập 2: Đếm Số Dương (Count Positive Numbers)

Đề bài: Nhập một dãy số nguyên. Đếm có bao nhiêu số dương (lớn hơn 0).

Problem: Enter a list of integers. Count how many are positive (greater than 0).

Ví dụ:

Enter numbers: -3 5 0 7 -1 2

Output:

Positive count: 3

Bài Tập 3: Tổng Các Phần Tử (Sum of Elements)

Đề bài: Nhập một dãy số nguyên trên một dòng (cách nhau bởi dấu cách). Tính và in tổng tất cả các phần tử.

Problem: Enter a list of integers on one line (separated by spaces). Calculate and print the sum of all elements.

Ví dụ:

Enter numbers: 3 7 2 5 1

Output:

Sum: 18

Bài Tập 4: In Ngược Danh Sách (Print List in Reverse)

Đề bài: Nhập một dãy số nguyên. In danh sách theo thứ tự ngược lại, trên cùng một dòng cách nhau bởi dấu cách.

Problem: Enter a list of integers. Print the list in reverse order, on one line separated by spaces.

Ví dụ:

Enter numbers: 1 2 3 4 5

Output:

5 4 3 2 1

Bài Tập 5: Tổng Số Lẻ (Sum of Odd Numbers)

Đề bài: Nhập một dãy số nguyên. Tính tổng CHỈ các số lẻ trong danh sách.

Problem: Enter a list of integers. Calculate sum of ONLY odd numbers in the list.

Ví dụ:

Enter numbers: 2 7 4 3 8 5

Output:

Sum of odd: 15

Level 2 - Trung Bình / Intermediate

Bài Tập 6: Loại Bỏ Trùng Lặp (Remove Duplicates)

Đề bài: Nhập một dãy số nguyên. In danh sách sau khi loại bỏ các phần tử trùng lặp (giữ thứ tự xuất hiện đầu tiên).

Problem: Enter a list of integers. Print list after removing duplicates (keep first occurrence order).

Ví dụ:

Enter numbers: 3 5 3 7 5 9 3

Output:

3 5 7 9

Bài Tập 7: Nén Phần Tử Liên Tiếp (Compress Consecutive Duplicates)

Đề bài: Nhập một dãy số nguyên. Nén các phần tử liên tiếp giống nhau thành (giá_trị, số_lần). In mỗi nhóm trên một dòng.

Problem: Enter a list of integers. Compress consecutive identical elements into (value, count). Print each group on a line.

Ví dụ:

Enter numbers: 1 1 1 2 2 3 3 3 3 1

Output:

1 x3
2 x2
3 x4
1 x1

Bài Tập 8: Tìm Số Lớn Thứ Hai (Find Second Largest)

Đề bài: Nhập một dãy số nguyên. Tìm và in số lớn thứ hai (không trùng với số lớn nhất).

Problem: Enter a list of integers. Find and print the second largest number (distinct from the largest).

Ví dụ:

Enter numbers: 5 9 3 9 7

Output:

Second largest: 7

Bài Tập 9: Phân Loại Dương và Âm (Separate Positive and Negative)

Đề bài: Nhập một dãy số nguyên. In hai dòng: dòng 1 là các số dương, dòng 2 là các số âm. Bỏ qua số 0.

Problem: Enter a list of integers. Print two lines: line 1 is positive numbers, line 2 is negative numbers. Skip zeros.

Ví dụ:

Enter numbers: 5 -3 0 8 -7 2 -1

Output:

Positive: 5 8 2
Negative: -3 -7 -1

Bài Tập 10: Tìm Cặp Số Có Tổng Bằng Target (Find Pairs with Target Sum)

Đề bài: Nhập một dãy số nguyên và một số target. Tìm và in tất cả các cặp (i, j) mà numbers[i] + numbers[j] = target (i < j).

Problem: Enter a list of integers and a target number. Find and print all pairs (i, j) where numbers[i] + numbers[j] = target (i < j).

Ví dụ:

Enter numbers: 2 7 4 5 3 1
Enter target: 6

Output:

2 + 4 = 6
5 + 1 = 6
3 + 3 = 6

ĐÁP ÁN / SOLUTIONS

Level 1 - Đáp Án

Solution 1: Nhân Đôi Phần Tử

Giải thích: Tạo danh sách kết quả, nhân đôi từng phần tử và thêm vào.

Explanation: Create result list, double each element and append.

Code:

python
numbers = list(map(int, input("Enter numbers: ").split())) result = [] for num in numbers: result.append(num * 2) print(" ".join(map(str, result)))

Solution 2: Đếm Số Dương

Giải thích: Duyệt danh sách, kiểm tra điều kiện dương và đếm.

Explanation: Iterate list, check positive condition and count.

Code:

python
numbers = list(map(int, input("Enter numbers: ").split())) count = 0 for num in numbers: if num > 0: count += 1 print(f"Positive count: {count}")

Solution 3: Tổng Các Phần Tử

Giải thích: Nhập dãy số bằng split(), duyệt qua từng phần tử và cộng dồn.

Explanation: Input numbers using split(), iterate through each element and accumulate sum.

Code:

python
numbers = list(map(int, input("Enter numbers: ").split())) total = 0 for num in numbers: total += num print(f"Sum: {total}")

Solution 4: In Ngược Danh Sách

Giải thích: Duyệt từ cuối về đầu bằng range ngược.

Explanation: Iterate from end to start using reverse range.

Code:

python
numbers = list(map(int, input("Enter numbers: ").split())) result = [] for i in range(len(numbers) - 1, -1, -1): result.append(numbers[i]) print(" ".join(map(str, result)))

Solution 5: Tổng Số Lẻ

Giải thích: Duyệt danh sách, chỉ cộng các số lẻ vào tổng.

Explanation: Iterate list, only add odd numbers to sum.

Code:

python
numbers = list(map(int, input("Enter numbers: ").split())) total = 0 for num in numbers: if num % 2 != 0: total += num print(f"Sum of odd: {total}")

Level 2 - Đáp Án

Solution 6: Loại Bỏ Trùng Lặp

Giải thích: Duyệt danh sách, chỉ thêm phần tử nếu chưa có trong danh sách kết quả.

Explanation: Iterate list, only append element if not already in result list.

Code:

python
numbers = list(map(int, input("Enter numbers: ").split())) result = [] for num in numbers: if num not in result: result.append(num) print(" ".join(map(str, result)))

Solution 7: Nén Phần Tử Liên Tiếp

Giải thích: Theo dõi giá trị hiện tại và đếm. Khi giá trị thay đổi, in kết quả và reset.

Explanation: Track current value and count. When value changes, print result and reset.

Code:

python
numbers = list(map(int, input("Enter numbers: ").split())) current = numbers[0] count = 1 for i in range(1, len(numbers)): if numbers[i] == current: count += 1 else: print(f"{current} x{count}") current = numbers[i] count = 1 print(f"{current} x{count}")

Solution 8: Tìm Số Lớn Thứ Hai

Giải thích: Tìm max, sau đó tìm max trong các phần tử khác max.

Explanation: Find max first, then find max among elements not equal to max.

Code:

python
numbers = list(map(int, input("Enter numbers: ").split())) max1 = numbers[0] for num in numbers: if num > max1: max1 = num max2 = None for num in numbers: if num != max1: if max2 is None or num > max2: max2 = num print(f"Second largest: {max2}")

Solution 9: Phân Loại Dương và Âm

Giải thích: Phân loại vào 2 danh sách riêng dựa trên dấu của số.

Explanation: Classify into 2 separate lists based on sign of number.

Code:

python
numbers = list(map(int, input("Enter numbers: ").split())) positive = [] negative = [] for num in numbers: if num > 0: positive.append(num) elif num < 0: negative.append(num) print("Positive: " + " ".join(map(str, positive))) print("Negative: " + " ".join(map(str, negative)))

Solution 10: Tìm Cặp Số Có Tổng Bằng Target

Giải thích: Dùng 2 vòng lặp lồng để thử tất cả các cặp có thể.

Explanation: Use nested loops to try all possible pairs.

Code:

python
numbers = list(map(int, input("Enter numbers: ").split())) target = int(input("Enter target: ")) found = False for i in range(len(numbers)): for j in range(i + 1, len(numbers)): if numbers[i] + numbers[j] == target: print(f"{numbers[i]} + {numbers[j]} = {target}") found = True if not found: print("No pairs found")