1.问题描述: 找出两个已序数组,是否含有相同数字。(快速算法) 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; }