Determine whether the two sorted arrays have the same number (17th week on-board task)

Source: Internet
Author: User

[Cpp]/** Copyright (c) 2012, School of Computer Science, Yantai University * All rights reserved. * file name: test. cpp * Author: Fan Lulu * Completion Date: July 15, December 21, 2012 * version: v1.0 ** input Description: none * Problem description: write a program to determine whether there are identical numbers in two ordered arrays. * Program output: the final result. * Problem Analysis: * Algorithm Design: omitted */# include <iostream> using namespace std; bool existthesame (int * a, int n1, int * B, int n2 ); int main () {int a [] = {,}; int B [] = {, 10}; int n1 = sizeof () /sizeof (a [0]); int n2 = sizeof (B)/sizeof (B [0]); bool flag = existthesame (a, n1, B, n2 ); if (flag = true) cout <"two sorted arrays contain the same number! \ N "; else cout <" two sorted arrays do not have the same number! \ N "; return 0;} bool existthesame (int * a, int n1, int * B, int n2) {int I, j; for (I = 0; I <n1; I ++) {for (j = 0; j <n2; j ++) {if (a [I] = B [j]) return true; else return false ;}}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.