Level 1 - Cơ Bản / Basics
Bài Tập 1: 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 2: 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 1Output:
Sum: 18Bài Tập 3: 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 5Output:
Sum of odd: 15Bài Tập 4: 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 5: 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 8Output:
6 10 4 16Level 2 - Trung Bình / Intermediate
Bài Tập 6: 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 7: Kiểm Tra Danh Sách Tăng Dần (Check if List is Sorted)
Đề bài: Nhập một dãy số nguyên. Kiểm tra xem danh sách có được sắp xếp tăng dần không. In 'Yes' hoặc 'No'.
Problem: Enter a list of integers. Check if the list is sorted in ascending order. Print 'Yes' or 'No'.
Ví dụ:
Enter numbers: 1 3 5 7 9Output:
Sorted: YesBài Tập 8: 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: 6Output:
2 + 4 = 6
5 + 1 = 6
3 + 3 = 6Bài Tập 9: Tìm Phần Tử Xuất Hiện Nhiều Nhất (Find Most Frequent Element)
Đề bài: Nhập một dãy số nguyên. Tìm phần tử xuất hiện nhiều lần nhất. Nếu có nhiều phần tử cùng số lần, in phần tử đầu tiên.
Problem: Enter a list of integers. Find the most frequent element. If there is a tie, print the first one encountered.
Ví dụ:
Enter numbers: 3 5 3 7 5 3 7Output:
Most frequent: 3 (3 times)Bài Tập 10: 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 -1ĐÁP ÁN / SOLUTIONS
Level 1 - Đáp Án
Solution 1: 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 2: 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:
pythonnumbers = list(map(int, input("Enter numbers: ").split())) total = 0 for num in numbers: total += num print(f"Sum: {total}")
Solution 3: 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:
pythonnumbers = 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}")
Solution 4: 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 5: 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:
pythonnumbers = list(map(int, input("Enter numbers: ").split())) result = [] for num in numbers: result.append(num * 2) print(" ".join(map(str, result)))
Level 2 - Đáp Án
Solution 6: 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 7: Kiểm Tra Danh Sách Tăng Dần
Giải thích: Duyệt từ phần tử thứ 2, so sánh với phần tử trước. Nếu vi phạm, đánh dấu False.
Explanation: Iterate from 2nd element, compare with previous. If violated, mark False.
Code:
pythonnumbers = list(map(int, input("Enter numbers: ").split())) is_sorted = True for i in range(1, len(numbers)): if numbers[i] < numbers[i - 1]: is_sorted = False break if is_sorted: print("Sorted: Yes") else: print("Sorted: No")
Solution 8: 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:
pythonnumbers = 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")
Solution 9: Tìm Phần Tử Xuất Hiện Nhiều Nhất
Giải thích: Đếm từng phần tử bằng vòng lặp lồng, theo dõi max.
Explanation: Count each element using nested loop, track maximum.
Code:
pythonnumbers = list(map(int, input("Enter numbers: ").split())) max_count = 0 max_num = numbers[0] for num in numbers: count = 0 for n in numbers: if n == num: count += 1 if count > max_count: max_count = count max_num = num print(f"Most frequent: {max_num} ({max_count} times)")
Solution 10: 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)))