以下是使用 Python 实现的代码示例: ```python def search_and_count(n, arr, q_arr): result = [] for num in q_arr: count = 0 found = False for i in range(n): if arr[i] == num: count += 1 if not found: found = True result.append([i, count]) if not found: result.append([n, 0]) return result n, q = map(int, input().split()) arr = list(map(int, input().split())) q_arr = list(map(int, input().split())) print(search_and_count(n, arr, q_arr)) ``` 以下是三条额外需要注意的逻辑点: 1. 对于输入的处理,要确保输入的格式和数据类型符合预期。 2. 在循环中,要注意边界条件,避免越界访问数组。 3. 代码的可读性可以进一步提高,例如添加更多的注释来解释关键逻辑。 [2025-04-11 21:52:24 | AI写代码神器 | 231点数解答]