【算法】找出两个已序数组,是否含有相同的数字
2011-06-29 16:15
417 查看
1.问题描述:
找出两个已序数组,是否含有相同数字。(快速算法)
2.代码解决:
找出两个已序数组,是否含有相同数字。(快速算法)
2.代码解决:
/* version 1.0 Created 16:15 2011-6-29 Author fan */ #include <iostream> using namespace std; bool SameNumber(int arrA[],int arrB[],int lengthA,int lengthB) { int i,j; i=0; j=0; while(i<lengthA &&j<lengthB) { if (arrA[i]<arrB[j]) i++; else if (arrA[i]>arrB[j]) j++; else return true; } return false; } void InputArray(int arrX[],int length) { int i; for (i=0;i<length;i++) { cin>>arrX[i]; } } int main() { int arrA[10]; int arrB[10]; int lengthA; int lengthB; cin>>lengthA; InputArray(arrA,lengthA); cin>>lengthB; InputArray(arrB,lengthB); if (SameNumber(arrA,arrB,lengthA,lengthB)) { cout<<"the two Array have the same number!"<<endl; } else { cout<<"the two Array don't have the same number!"<<endl; } return 0; }
相关文章推荐
- 【算法题】找出两个已序数组,是否含有相同的数字
- 给定两个排好序的整型数组,怎么判断它们是否含有相同的数字?
- 第16周项目4 判断两个有序数组中是否含有相同数字
- 每天一道算法题-1 找出数组中两个只出现一次的数字
- 判断两个有序数组中是否有相同的数字(第十七周上机任务)
- js中比较两个数组中是否含有相同的元素,可去重,可删除合并为新数组
- 【算法题】找出一个整型数组里两个不同数字
- 查找算法之查找一个数组中两两数字相同,只有其中两个数字是不一样的,将其找出
- 十六周——判断两个有序数组中是否存在相同的数字
- 请教一个算法问题,有两个数组A,B,判断A中是否至少有一个元素和B中元素相同
- 判断两个有序数组中是否存在相同的数字
- 经典算法学习——快速找出数组中两个数字,相加等于某特定值
- 判断两个数组中是否含有相同的元素
- 比较两个有序数组中是否有相同数字
- js中比较两个数组中是否含有相同的元素,可去重,可删除合并为新数组
- 算法系列-两个有序数组中相同的数字
- 算法--找出数组中两个只出现一次的数字
- 用指针判断两个数组是否有相同的数字
- 每天一道算法题10 找出数组中两个只出现一次的数字
- 两个有n个数的整数数组,都排好序了。 用O(n)的时间查找两个数组是否有相同的数字。