搜索数组并比较它们
searching an array and compare them
写一个程序,从用户(max。各50人)。第一个数组的长度应该大于第二个;然后检查第二个数组中的所有成员是否存在在第一个,以相同的顺序,不管距离之间第一个数组中的成员。最后,程序告诉用户是否条件是否开启
数组的长度没有区别,只要您知道它们的长度。无论如何,你都要检查一下是否越过了他们。
这是一个算法:
if length of array2 is greater than 1, end. // All of array can't be in array 1.
// Find the first element of array 2 that is in array 1:
// Note: this only searches up to array1.length - array2.length,
// because of the restriction of ordering and length of array 2.
key = first element of array 2.
found = false;
for (index = 0; index < (array1.length - array2.length); ++index)
if (array[index] == key) then found = true, break out of loop.
end-for
if not found, end. // No use in detailed searching.
// Now compare the elements of the two arrays, one by one,
// starting with the second element of array2 and the element
// of array1 at (index + 1).
有更有效的算法,但这应该让你开始,直到有人发布确切的代码,所以你不必自己做任何工作。
相关文章:
- 比较字符数组
- For 循环仅比较数组的第一部分而不是整个数组
- C 比较数组中的元素并打印位置
- 如何在C++中比较数组中字符串的一部分的字符串
- 通过比较数组中的相邻元素来计算交换次数
- 在同时添加和删除匹配项的同时比较数组中的项
- 在 C++ 中比较数组的元素
- 比较数组C++中单词列表中的单词
- 如何使用 == 运算符来比较数组的元素
- 比较数组中的随机值
- 警告:在 C++ 中比较数组和字符串
- 如何在Qt单元测试中比较数组
- 比较数组的最佳方式
- 如何比较数组内部的值
- 如何用C或C++比较数组中的内容
- 比较数组的所有元素
- 比较数组中的值并删除较大的值
- 快速比较数组和数字
- 比较数组中的项
- C++ 比较数组中的两个值并获取更大的下标数