http://acm.nyist.net/JudgeOnline/problem.php?pid=626

intersection set

时间限制:1000 ms  |  内存限制:65535 KB
难度:1
 
描述
两个集合,你只需要求出两个集合的相同元素,并输出个数。
 
输入
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的更多相关文章

  1. [LeetCode] Intersection of Two Arrays II 两个数组相交之二

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  2. [LeetCode] Intersection of Two Arrays 两个数组相交

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  3. [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 ...

  4. 【leetcode】Intersection of Two Linked Lists

    题目简述: Write a program to find the node at which the intersection of two singly linked lists begins. ...

  5. [LintCode] Intersection of Two Linked Lists 求两个链表的交点

    Write a program to find the node at which the intersection of two singly linked lists begins. Notice ...

  6. LeetCode Intersection of Two Arrays

    原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays/ 题目: Given two arrays, write a func ...

  7. Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  8. LeetCode Intersection of Two Arrays II

    原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays-ii/ 题目: Given two arrays, write a f ...

  9. nyist 78 圈水池

    http://acm.nyist.net/JudgeOnline/problem.php?pid=78 圈水池 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 有一个 ...

随机推荐

  1. android studio 出错

    http://blog.csdn.net/dhx20022889/article/details/44919905

  2. http响应状态码301和302

    HTTP返回码中301与302的区别 (2012-10-15 22:06:09) 一.官方说法 301,302 都是HTTP状态的编码,都代表着某个URL发生了转移,不同之处在于: 301 redir ...

  3. Git版本控制

    官方文档:http://git-scm.com/book/en/v2 github :https://guides.github.com/activities/hello-world/ How to ...

  4. Asp.net forms认证注意事项

    1.N台服务器配置文件的相关配置要一致 <authentication mode="Forms"> <forms timeout="3600" ...

  5. DOM、SAX、JDOM、DOM4J四种XML解析方法PK

    基础方法(指不需要导入jar包,java自身提供的解析方式):DOM.SAXDOM:是一种平台无关的官方解析方式   --优点:          (1)形成了树结构,直观好理解,代码更易编写     ...

  6. C++ 自动指针 共享指针

    #include <iostream> #include <string> #include <memory> class Item { public: Item( ...

  7. 内存分配、C++变量的生命周期和作用域

    1.内存分配 程序的内存分配有以下几个区域:堆区.栈区.全局区.程序代码区,另外还有文字常量区. 栈区 ——存放局部变量,即由auto修饰的变量,一般auto省略.由编译器自动分配释放.局部变量定义在 ...

  8. Effective Project Communications

    I was recently invited to speak at a conference in Singapore on Effective Project Communications. I' ...

  9. Be a Smart Project Manager

    The key to being a smart project manager is to remember how you are going to manage your project, to ...

  10. 控制台打印出event对象时,对象里面的currentTarget为null

    但是MouseEvent对象展开时 附上老外的解释~~~: http://stackoverflow.com/questions/26496176/when-loggin-an-event-objec ...