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. nrf51822裸机教程-UART

    art硬件模块通常都有内置的硬件接收buff,比如51822的硬件uart模块图如下 因为通常接收到uart数据时都会做一些处理.比如保存到数据,或者对数据做一些判断之类的. 如果uart的波特率设置 ...

  2. 浅谈ASP.Net ProcessPostData方法

    其实这两次方法做的都是同一件事儿,让我们来看下图片中的代码,唯一的区别就是两次传入的参数不一样,一个是postData集合和Page_Load加载前的标记,另一个是leftoverPostData集合 ...

  3. C#程序读取数据库中包含null的列的值

    private void btn2_Click(object sender, RoutedEventArgs e)         {             using (SqlConnection ...

  4. 其他常用HTML 片段

    1.input placeholder 文字居中 字体大小+上下padding值等于设计稿宽度 设计稿中总高度为86px   padding:27px 0;font-size:30px;   2.英文 ...

  5. asp.net字符串的数学表达式计算结果

    using System; using System.Collections.Generic; using System.Web; using System.CodeDom.Compiler; usi ...

  6. appium关于定位元素

    Windows上定位元素我用的是uiautomatorviewer 这个工具在你的SDK-tools目录下,点击uiautomatorviewer.bat启动,注意appium在跑的时候是取不到的 工 ...

  7. Rails进阶参考

    https://gist.github.com/xdite/4044f3a037de029bc35c From idea to products: - Ideation, wireframes, mo ...

  8. Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number. An example is the root-to-leaf path1->2->3which represents the number123. Find the total sum of a

    class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } public class ...

  9. mybatis的xlm的sql

    <sqlMap namespace="egis.scms.order">    <typeAlias alias="ScmsOrderDTO" ...

  10. 《JAVA NIO》第二章缓冲区

    1.缓冲区的构成 2.缓冲区的类图 3.ByteBuffer ByteBuffer是直接和Channel打交道的,准确的是直接字节缓冲. 问题:直接字节缓冲区和内存映射的关系 4.ByteOrder ...