描述

Jack and Jill have decided to sell some of their Compact Discs, while they still have some value. They have decided to sell one of each of the CD titles that they both own. How many CDs can Jack and Jill sell?

Neither Jack nor Jill owns more than one copy of each CD.

输入

The input consists of a sequence of test cases. The first line of each test case contains two non-negative integers N and M, each at most one million, specifying the number of CDs owned by Jack and by Jill, respectively. This line is followed by N lines listing the catalog numbers of the CDs owned by Jack in increasing order, and M more lines listing the catalog numbers of the CDs owned by Jill in increasing order. Each catalog number is a positive integer no greater than one billion. The input is terminated by a line containing two zeros. This last line is not a test case and should not be processed.

输出

For each test case, output a line containing one integer, the number of CDs that Jack and Jill both own.

样例输入

3 3
1
2
3
1
2
4
0 0

样例输出

2

#include<cstring>
#include<cstdio>
using namespace std;
int a[],n;
int ok(int x)
{
int bot=;
int top=n;
int mid;
while(bot<=top)
{
mid=(bot+top)/;
if(x<a[mid])
top=mid-;
else if(x>a[mid])
bot=mid+;
else
return ;
}
return ;
}
int main()
{
int m,i,x,s;
while(scanf("%d%d",&n,&m),m||n)
{
memset(a,,sizeof(a));
s=;
for(i=;i<=n;i++)
scanf("%d",&a[i]);
for(i=;i<=m;i++)
{
scanf("%d",&x);
s=s+ok(x);
}
printf("%d\n",s);
}
return ;
}

最新文章

  1. Entity Framework 6 Recipes 2nd Edition(13-2)译 -&gt; 用实体键获取一个单独的实体
  2. python爬虫学习(7) —— 爬取你的AC代码
  3. opencv单目摄像机标定(一)
  4. php 数据访问(以mysql数据库为例)
  5. 使用substring和split方法从字符串中抽取一组清单
  6. [转] Windows下使用Python读取Excel表格数据
  7. hadoop2.2编程: SequenceFileWritDemo
  8. Android手势操作
  9. ScrollView嵌套listview 时根据内容动态设置listview高度
  10. linux mysql密码破解一张图解释
  11. Django Web开发【3】创建网络收藏夹
  12. Cenots安装openvpn、pam_mysql进行用户认证和流量控制
  13. 剑指offer——矩阵覆盖(斐波那契变形)
  14. 百度AI开放平台- API实战调用
  15. MySQL常用配置参数
  16. Java集合中的LinkedHashMap类
  17. CentOS 远程桌面相关服务安装笔记
  18. Golang 知识点总结
  19. python3+selenium入门13-操作cookie
  20. Django 框架 Form组件

热门文章

  1. PAT 1056 Mice and Rice
  2. HTML &lt;frameset&gt; 标签
  3. http状态码汇总及代表意思
  4. javascript实现数据结构:线索二叉树
  5. C++基础--字符串倒序输出
  6. CSS3布局样式
  7. App后台开发架构实践笔记
  8. java面试题之----HashMap常见面试题总结
  9. asyncio标准库4 asyncio performance
  10. SQL Server -&gt;&gt; 生成时间类型的Partition Function和Partition Scheme代码