zoukankan      html  css  js  c++  java
  • (TOJ3114){A}∩{B}

    描述

    Given two integer sets A and B sorted descendingly, you are asked to output the element count of A∩B.

    输入

    Standard input will contain multiple test cases. The first line of the input is a single integrate T (1 <= T <= 50) which is the number of test cases. then T consecutive test cases followed. In each test case, there has four lines. The first line contains the element count N(1<=N<=100000) for the first set. The second line contains N integers in the first set.
    The third line contains the element count M(1<=M<=100000) for the second set. The fourth line contains M integers in the second set.

    NOTE: there will be no duplicate elements in each sets and all the integers in each set have been sorted descendingly.

    输出

    For each test case in the input, there's only one line output that contains the element count of the intesection of the two sets.

    样例输入

    1
    5
    5 4 3 2 1
    4
    5 3 1 -1

    样例输出

    3
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<ctype.h>
     4 #include<math.h>
     5 
     6 int a[100001],b[100001];
     7 
     8 void deal(int c[], int n, int d[], int m)
     9 {
    10     int i,j,flag;
    11     flag=i=j=0;
    12     while(i<n && j<m){
    13         if(c[i]<d[j]){j++;}
    14         else if(c[i]==d[j]){
    15             flag++;
    16             i++; j++;
    17         }else{
    18           i++;    
    19         }
    20     }
    21     printf("%d\n",flag);
    22 }
    23 
    24 void solve()
    25 {
    26     int T,n,m,i;
    27     scanf("%d",&T);
    28     while(T--){
    29         scanf("%d",&n);
    30         for(i=0; i<n; i++){
    31             scanf("%d",&a[i]);
    32         }
    33         scanf("%d",&m);
    34         for(i=0; i<m; i++){
    35             scanf("%d",&b[i]);
    36         }
    37         deal(a,n,b,m);        
    38     }
    39 }
    40 
    41 int main()
    42 {
    43     solve();
    44     return 0;
    45 }
     
  • 相关阅读:
    hortonworks
    使用Ambari快速部署Hadoop大数据环境
    js模板引擎
    Scala中的语言特性是如何实现的2
    IOS多线程编程一:概述
    Struts框架
    总体设计
    算法介绍
    社区与关怀
    从C#的Singleton设计模式
  • 原文地址:https://www.cnblogs.com/xueda120/p/3095045.html
Copyright © 2011-2022 走看看