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 5

Output:

Maximum: 9

Bà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 1

Output:

Sum: 18

Bài Tập 3: Đế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: 6

Output:

Count: 3

Bài Tập 4: 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

Bà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 5

Output:

5 4 3 2 1

Level 2 - Trung Bình / Intermediate

Bài Tập 6: 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

Bài Tập 7: 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 8: 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 9

Output:

Sorted: Yes

Bài Tập 9: Ghép Xen Kẽ Hai Danh Sách (Interleave Two Lists)

Đề bài: Nhập hai dãy số nguyên. In danh sách mới bằng cách xen kẽ phần tử từ hai danh sách. Nếu một danh sách dài hơn, thêm phần còn lại vào cuối.

Problem: Enter two lists of integers. Print new list by interleaving elements from both. If one is longer, append remaining elements.

Ví dụ:

Enter list 1: 1 3 5
Enter list 2: 2 4 6 8

Output:

1 2 3 4 5 6 8

Bài Tập 10: 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

ĐÁ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:

python
numbers = 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:

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

Solution 3: Đế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:

python
numbers = 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 4: 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}")

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:

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)))

Level 2 - Đáp Án

Solution 6: 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")

Solution 7: 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 8: 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:

python
numbers = 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 9: Ghép Xen Kẽ Hai Danh Sách

Giải thích: Xen kẽ đến hết danh sách ngắn hơn, sau đó nối phần còn lại.

Explanation: Interleave until shorter list ends, then append remaining elements.

Code:

python
list1 = list(map(int, input("Enter list 1: ").split())) list2 = list(map(int, input("Enter list 2: ").split())) result = [] min_len = min(len(list1), len(list2)) for i in range(min_len): result.append(list1[i]) result.append(list2[i]) for i in range(min_len, len(list1)): result.append(list1[i]) for i in range(min_len, len(list2)): result.append(list2[i]) print(" ".join(map(str, result)))

Solution 10: 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}")