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 }
     
  • 相关阅读:
    postgresql 主从复制并切换
    执行sql中的 函数,function
    读取Core下的appsettings.json的值的时候中文乱码
    Core 定时任务之HangFire
    7 ~ express ~ body-parser 模块的使用
    6 ~ express ~ 搭建用户注册前端页面
    5 ~ express ~ 连接数据库
    4 ~ express ~ 划分模块开发
    3 ~ express ~ 静态文件托管
    2 ~ express ~ 模板引擎的配置与使用
  • 原文地址:https://www.cnblogs.com/xueda120/p/3095045.html
Copyright © 2011-2022 走看看