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. BAE3.0上的java+tomcat+hibernate代码发布

    在BAE上使用hibernate说起来也简单,但因为一个不小心,耽误了好几个小时. 百度文档中有说: http://developer.baidu.com/wiki/index.php?title=d ...

  2. Android 一键直接查看Sqlite数据库数据

    转自:http://www.cnblogs.com/trinea/archive/2012/11/16/2773656.html 本文主要介绍Android开发中如何一键直接查看sqlite数据库中的 ...

  3. correctly handle PNG transparency in Win IE 5.5 & 6.

    function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6. { var arVersion = ...

  4. java JDK8 学习笔记——助教学习博客汇总

    java JDK8 学习笔记——助教学习博客汇总 1-6章 (by肖昱) Java学习笔记第一章——Java平台概论 Java学习笔记第二章——从JDK到IDEJava学习笔记第三章——基础语法Jav ...

  5. Qt与VS2005/2008的完美配合(自己编译Qt4.5.1的详细步骤)

    介绍 用过Linux的人想必都知道Qt(不是QuickTime,呵呵)这个名称,KDE就是用Qt写的,我也是接触Linux后才认识它的. Qt原先是奇趣科技TM(Trolltech)的产品,由Haav ...

  6. 从高版本JDK换成低版本JDK报错Unsupported major.minor version 52.0

    ava.lang.UnsupportedClassVersionError: PR/Sort : Unsupported major.minor version 52.0这个错误是由于高版本的java ...

  7. LeetCode Flip Game II

    原题链接在这里:https://leetcode.com/problems/flip-game-ii/ 题目: You are playing the following Flip Game with ...

  8. 北大,awk 命令基础练习

    北大,awk 命令基础练习 Red Hat Enterprise Linux Version 5.3 Get the latest news about the world's Open Source ...

  9. php 读取webservice接口

    开启 extension = php_soap.dll extension = php_curl.dll extension = php_openssl.dll <script src=&quo ...

  10. 用NPOI操作EXCEL关于HSSFClientAnchor(dx1,dy1,dx2,dy2,col1,row1,col2,row2)的参数

    2.4.1 用NPOI操作EXCEL关于HSSFClientAnchor(dx1,dy1,dx2,dy2,col1,row1,col2,row2)的参数   NPOI教程:http://www.cnb ...