nyist 626 intersection set
http://acm.nyist.net/JudgeOnline/problem.php?pid=626
intersection set
- 描述
- 两个集合,你只需要求出两个集合的相同元素,并输出个数。
- 输入
- m n
{a1 , a2 , a3 , a4 … ai … am}
{b1 , b2 , b3 , b4 … bi … bn}
1 <= n , m <= 50000 , 保证一个集合中不会输入重复数据
0 <= ai , bi <= 100000
多组测试数据 - 输出
- 一行一个数据,为两个集合中相同的元素个数
- 样例输入
-
8 8
1 5 6 9 10 12 16 59
5 6 9 8 15 17 65 98 - 样例输出
-
3 分析:
把两组数据直接存到一个数组里,sort排序去重即可。
AC代码:
#include <stdio.h>
#include <algorithm>
using namespace std;
int num[];
int main()
{
int m,i,n,count;
while(~scanf("%d %d",&m,&n))
{
count=;
for(i=;i<m+n;i++)
scanf("%d",&num[i]);
sort(num,num+m+n);
for(i=;i<n+m-;i++)
if(num[i]==num[i+])
count++;
printf("%d\n",count);
}
return ;
}
nyist 626 intersection set的更多相关文章
- [LeetCode] Intersection of Two Arrays II 两个数组相交之二
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- [LeetCode] Intersection of Two Arrays 两个数组相交
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- [LeetCode] Intersection of Two Linked Lists 求两个链表的交点
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- 【leetcode】Intersection of Two Linked Lists
题目简述: Write a program to find the node at which the intersection of two singly linked lists begins. ...
- [LintCode] Intersection of Two Linked Lists 求两个链表的交点
Write a program to find the node at which the intersection of two singly linked lists begins. Notice ...
- LeetCode Intersection of Two Arrays
原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays/ 题目: Given two arrays, write a func ...
- Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- LeetCode Intersection of Two Arrays II
原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays-ii/ 题目: Given two arrays, write a f ...
- nyist 78 圈水池
http://acm.nyist.net/JudgeOnline/problem.php?pid=78 圈水池 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 有一个 ...
随机推荐
- springMVC框架下——通用接口之图片上传接口
我所想要的图片上传接口是指服务器端在完成图片上传后,返回一个可访问的图片地址. spring mvc框架下图片上传非常简单,如下 @RequestMapping(value="/upload ...
- 【转】JavaScript中的this关键字使用的四种调用模式
http://blog.csdn.net/itpinpai/article/details/51004266 this关键字本意:这个.这里的意思.在JavaScript中是指每一个方法或函数都会有一 ...
- java FileWriter and FileReader
import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class FWFRD ...
- IOS NSDate NSDateFormatter 导致相差8小时
时间问题应该是所有编程语言都要处理的.详细学过php的同学知道,php中也会有相差8小时的问题,然而php可以非常方便的解决的,直接设置下就好了 我最近在学习IOS的过程中,发现IOS的日期处理也是个 ...
- [qemu] 在前端驱动使用virtio的情况下,如何让后端使用vhost-user [未解决]
首先,如果你更关心原理和知识,请读读这个 http://chuansong.me/n/2186528 (值得细细的逐字读). 在<<深入浅出dpdk>>中提到,vhost-us ...
- 下载大图的demo by apple,值得研究和参考
https://developer.apple.com/library/content/samplecode/LargeImageDownsizing/Introduction/Intro.html ...
- 弄清const与指针、引用之间的关系
const和 define在常量定义上的差别 在C++中,我们可以使用const 或者 宏define来定义常量.但是C++鼓励使用const定义常量,而不是宏define.原因有很多. 1.defi ...
- ASP.NET中 WebForm 窗体控件使用及总结【转】
原文链接:http://www.cnblogs.com/ylbtech/archive/2013/03/06/2944675.html ASP.NET中 WebForm 窗体控件使用及总结. 1.A, ...
- 几个简单的html+css+js题目
1.页面中有一图片,请在下划线处添加代码能够实现隐藏该图片的功能 <img id="pic" src="door.jpg" width="200 ...
- SqlServer2008R2 修改表中列为自增列
选定列,修改列属性标识规范中(是标识)为是,标识增量为1,标识种子为1 SQL语句:alter table 表名 add 列名 int IDENTITY(1,1) NOT NULL