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 }
     
  • 相关阅读:
    问题:https与http有什么区别啊?
    Android应用开发是否应避免使用枚举?
    AppStore 内购验证的方法
    vs2017环境下编译log4cpp-1.1.3
    iphone开发笔记
    系统界面跳转设置[转]
    常用宏OC
    git忽略文件
    第三方开源库学习
    [转]iOS开发总结之代码规范
  • 原文地址:https://www.cnblogs.com/xueda120/p/3095045.html
Copyright © 2011-2022 走看看