第十六周OJ平台Problem B: 有相同数字?
来源:互联网 发布:淘宝积分卖家页面 编辑:程序博客网 时间:2024/06/05 20:44
Description
输入两个数组中要存放的元素个数及元素值(不超过50个),判断这两个数组中是否有相同的数字。
在下面的程序基础上完成:
#include<iostream>
using namespace std;
bool existthesame(int *a,int n1,int *b,int n2); //n1个数据的a数组中和n2个数据的b数组中是否有相同元素
int main()
{
int a[50];
int b[50];
int i, n1, n2;
//读入数据
……
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)
{
}
Input
共有两组数。每组数包括:这组数的个数n,以及这n个数字。(n<=50)
Output
当两组数中有相同数字时,输出YES,否则,输出NO
Sample Input
6 1 7 8 10 12 174 2 7 12 25
Sample Output
YES
代码
<pre class="html" name="code">#include<iostream>using namespace std;bool existthesame(int *a,int n1,int *b,int n2); //n1个数据的a数组中和n2个数据的b数组中是否有相同元素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){ int i,j; for (i=0; i<n1; i++) { for (j=0; j<n2-i+1; j++) { if (*(a+i)==*(b+j)) return true; } }}
运行结果:
学习心得:
好好学习 天天向上
0 0
- 第十六周OJ平台Problem B: 有相同数字?
- 第十六周OJ 项目Problem B: 有相同数字?
- 第十六周 OJ平台-有相同数字?
- 第十六周 oj平台 有相同数字?
- 第十六周OJ平台 Problem C: 相同的数字!
- 第十六周OJ(B)——有相同数字?
- 第十六周OJ项目B:有相同数字?
- 第十六周 Problem B:有相同的数字
- 第十六周oj平台(2):有相同数字?
- 第十六周 OJ平台-相同的数字!
- 第十六周 oj平台 相同的数字
- 第十六周oj--有相同数字?
- 第十六周 OJ 有相同数字?
- 第十六周 OJ 有相同数字!
- 第十六周 OJ:有相同数字!
- 第十六周 OJ:有相同数字?
- 第16周 oj平台<问题 B: 有相同数字?>
- 第十六周 问题 B: 有相同数字?
- 关于js二级联动的实现
- 20141215 N2
- Java并发编程:Timer和TimerTask(转载)
- leetcode解题思路
- 检验员年终总结范文2013年银行柜员个人年终总结
- 第十六周OJ平台Problem B: 有相同数字?
- 软件架构原则
- 五个不为人知的ESC键妙用
- 17周项目二 指针玩字符串1-1 数组做形参实现连接
- 客户经理年终总结人事专员年终总结范文
- 解锁不能复制的网页
- 关于动态内存分配和数组的选用(变长选malloc,定长选数组)
- win7 C++ImageMagick配置
- 数据挖掘之路