第17周项目-有相同的数字?
2012-12-20 16:41
253 查看
/* * Copyright (c) 2012, 烟台大学计算机学院 * All rights reserved. * 文件名称:test.cpp * 作 者:徐凯旋 * 完成日期:2012 年 12 月 20 日 * 版 本 号:v 1.0 */ #include<iostream> using namespace std; bool existthesame(int *a,int n1,int *b,int n2); int main() { int a[]={1,4,7,8}; int b[]={2,5,6,9,10}; int n1=sizeof(a)/sizeof(a[0]); int n2=sizeof(b)/sizeof(b[0]); bool flag=existthesame(a,n1,b,n2); if(flag==true) cout<<"两个有序数组中存在相同的数字!\n"; else cout<<"两个有序数组中不存在相同的数字!\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; } return 0; }
运行结果:
#include<iostream> using namespace std; bool existthesame(int *a,int n1,int *b,int n2); int main() { int a[]={1,4,7,8}; int b[]={1,4,7,8}; int n1=sizeof(a)/sizeof(a[0]); int n2=sizeof(b)/sizeof(b[0]); bool flag=existthesame(a,n1,b,n2); if(flag==true) cout<<"两个有序数组中存在相同的数字!\n"; else cout<<"两个有序数组中不存在相同的数字!\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; } return 0; }
运行结果:
相关文章推荐
- C++第17周项目3——有相同数字?
- 第十六周项目4-两个数组中是否有相同数字
- 第16周项目8-有相同数字?
- 第十六周-(项目四)有相同的数字吗?
- 第16周项目4:有相同数字?
- 第十六周OJ项目B:有相同数字?
- 第十六周 项目4--有相同数字吗?
- 第十六周项目4-有相同数字?
- 第十七周项目三—判断相同数字
- 第十六周OJ 项目 Problem C: 相同的数字!
- 第17周项目2⑦--是否有相同字符
- 第十六周OJ项目三相同的数字
- 第十六周OJ项目3相同数字!
- 【指针】16周项目四。判断两个有序数组中是否存在相同的数字
- 第十六周 项目四 两个数组中是否有相同的数字
- 第十六周项目3-有相同数字?
- 第16周oj项目2有相同数字?
- 17周项目3-有相同数字?
- 第十六周项目3-有相同数字?
- 第16周项目4 判断两个有序数组中是否含有相同数字