第十六周 Problem B:有相同的数字
2014-12-14 14:44
134 查看
/* *Copyright (c)2014,烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:grade.cpp *作 者:刘天恩 *完成日期:2014年12月14日 *版 本 号:v1.0 *问题描述:输入两个数组中要存放的元素个数及元素值(不超过50个),判断这两个数组中是否有相同的数字。 *程序输入:无 *程序输出:YES OR NO */ #include<iostream> using namespace std; bool existthesame(int *a,int n1,int *b,int n2); int main() { int a[50]; int b[50]; int i, n1, n2; cin>>n1; for(i=0; i<n1; ++i) cin>>a[i]; cin>>n2; for(i=0; i<n2; ++i) cin>>b[i]; bool flag=existthesame(a,n1,b,n2); if(flag==true) cout<<"YES\n"; else cout<<"NO\n"; return 0; } bool existthesame(int *a,int n1,int *b,int n2) { bool existthesame=false; int i,j; for(i=0; i<n1; ++i) for(j=0; j<n2; ++j) { if(a[i]==b[j]) { existthesame=true; } } return existthesame; }
运行结果:
相关文章推荐
- 第十六周OJ 项目 Problem C: 相同的数字!
- 第十六周 Problem C:相同的数字
- 第十六周OJ平台 Problem C: 相同的数字!
- 第十六周OJ平台Problem B: 有相同数字?
- 第十六周OJ 项目Problem B: 有相同数字?
- 第十六周项目4-有相同数字?
- 第十六周OJ项目三相同的数字
- 第十六周OJ项目2有相同数字?
- 第十六周 OJ第二题--有相同数字?
- 第十六周OJ项目二有相同数字?
- 第十六周OJ项目二——有相同的数字
- 第十六周OJ(C)——有相同数字 !
- 第十六周OJ题目(2)——有相同数字?
- 第十六周oj--有相同数字?
- 第十六周 项目四 两个数组中是否有相同的数字
- 第十六周 项目4--有相同数字吗?
- 第十六周 问题 C: 相同的数字!
- 第十六周 OJ 有相同数字?
- 第十六周OJ——2 有无相同数字
- 第十六周 OJ第三题--相同的数字!