Level 1 - Cơ Bản / Basics
Bài Tập 1: Tìm Số Nhỏ Nhất (Find Minimum)
Đề bài: Nhập một dãy số nguyên. Tìm và in số nhỏ nhất trong danh sách.
Problem: Enter a list of integers. Find and print the smallest number in the list.
Ví dụ:
Enter numbers: 8 3 9 1 5Output:
Minimum: 1Bài Tập 2: In Số Chẵn Trong Danh Sách (Print Even Numbers from List)
Đề bài: Nhập một dãy số nguyên. Chỉ in ra các số chẵn, mỗi số trên một dòng.
Problem: Enter a list of integers. Print only even numbers, one per line.
Ví dụ:
Enter numbers: 3 8 5 12 7 4Output:
8
12
4Bài Tập 3: Tìm Số Lớn Nhất (Find Maximum)
Đề bài: Nhập một dãy số nguyên. Tìm và in số lớn nhất trong danh sách.
Problem: Enter a list of integers. Find and print the largest number in the list.
Ví dụ:
Enter numbers: 4 9 2 7 5Output:
Maximum: 9Bài Tập 4: Đếm Số Lớn Hơn Một Giá Trị (Count Greater Than Value)
Đề bài: Nhập một dãy số nguyên, sau đó nhập một số k. Đếm có bao nhiêu phần tử trong danh sách lớn hơn k.
Problem: Enter a list of integers, then enter a number k. Count how many elements are greater than k.
Ví dụ:
Enter numbers: 5 12 3 8 15 7
Enter k: 6Output:
Count: 3Bài Tập 5: 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 5Output:
5 4 3 2 1Level 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 3Output:
3 5 7 9Bà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 1Output:
1 x3
2 x2
3 x4
1 x1Bài Tập 8: 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 -1Output:
Positive: 5 8 2
Negative: -3 -7 -1Bài Tập 9: Trung Bình và Đếm Trên Trung Bình (Average and Count Above Average)
Đề bài: Nhập một dãy số nguyên. Tính trung bình, sau đó đếm có bao nhiêu phần tử lớn hơn trung bình.
Problem: Enter a list of integers. Calculate average, then count how many elements are above average.
Ví dụ:
Enter numbers: 2 8 4 6 10Output:
Average: 6.0
Above average: 2Bài Tập 10: Xoay Danh Sách (Rotate List)
Đề bài: Nhập một dãy số nguyên và một số k. Xoay danh sách sang phải k vị trí. Ví dụ: xoay [1,2,3,4,5] sang phải 2 vị trí → [4,5,1,2,3].
Problem: Enter a list of integers and a number k. Rotate list right by k positions. Example: rotate [1,2,3,4,5] right by 2 → [4,5,1,2,3].
Ví dụ:
Enter numbers: 1 2 3 4 5
Enter k: 2Output:
4 5 1 2 3ĐÁP ÁN / SOLUTIONS
Level 1 - Đáp Án
Solution 1: Tìm Số Nhỏ Nhất
Giải thích: Tương tự tìm max nhưng so sánh nhỏ hơn.
Explanation: Similar to finding max but compare for smaller.
Code:
pythonnumbers = list(map(int, input("Enter numbers: ").split())) min_val = numbers[0] for num in numbers: if num < min_val: min_val = num print(f"Minimum: {min_val}")
Solution 2: In Số Chẵn Trong Danh Sách
Giải thích: Duyệt và kiểm tra chia hết cho 2, in nếu đúng.
Explanation: Iterate and check divisibility by 2, print if true.
Code:
pythonnumbers = list(map(int, input("Enter numbers: ").split())) for num in numbers: if num % 2 == 0: print(num)
Solution 3: Tìm Số Lớn Nhất
Giải thích: Khởi tạo max bằng phần tử đầu, duyệt và cập nhật khi gặp số lớn hơn.
Explanation: Initialize max with first element, iterate and update when finding larger number.
Code:
pythonnumbers = list(map(int, input("Enter numbers: ").split())) max_val = numbers[0] for num in numbers: if num > max_val: max_val = num print(f"Maximum: {max_val}")
Solution 4: Đếm Số Lớn Hơn Một Giá Trị
Giải thích: Duyệt danh sách, đếm phần tử lớn hơn k.
Explanation: Iterate list, count elements greater than k.
Code:
pythonnumbers = list(map(int, input("Enter numbers: ").split())) k = int(input("Enter k: ")) count = 0 for num in numbers: if num > k: count += 1 print(f"Count: {count}")
Solution 5: 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:
pythonnumbers = 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)))
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:
pythonnumbers = 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:
pythonnumbers = 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: 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:
pythonnumbers = 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 9: Trung Bình và Đếm Trên Trung Bình
Giải thích: Tính trung bình trước, sau đó duyệt lại đếm phần tử vượt trung bình.
Explanation: Calculate average first, then iterate again to count elements above average.
Code:
pythonnumbers = list(map(int, input("Enter numbers: ").split())) total = 0 for num in numbers: total += num average = total / len(numbers) count = 0 for num in numbers: if num > average: count += 1 print(f"Average: {average}") print(f"Above average: {count}")
Solution 10: Xoay Danh Sách
Giải thích: Chia danh sách tại vị trí len-k, đặt phần cuối lên trước.
Explanation: Split list at position len-k, place tail before head.
Code:
pythonnumbers = list(map(int, input("Enter numbers: ").split())) k = int(input("Enter k: ")) k = k % len(numbers) result = [] for i in range(len(numbers) - k, len(numbers)): result.append(numbers[i]) for i in range(len(numbers) - k): result.append(numbers[i]) print(" ".join(map(str, result)))