zoukankan      html  css  js  c++  java
  • Kattis

    CD

    Jack and Jill have decided to sell some of their Compact Discs, while they still have some value. They have decided to sell one of each of the CD titles that they both own. How many CDs can Jack and Jill sell?

    Neither Jack nor Jill owns more than one copy of each CD.

    Input

    The input consists of a sequence of test cases. The first line of each test case contains two non-negative integersNN and MM, each at most one million, specifying the number of CDs owned by Jack and by Jill, respectively. This line is followed by NN lines listing the catalog numbers of the CDs owned by Jack in increasing order, and MMmore lines listing the catalog numbers of the CDs owned by Jill in increasing order. Each catalog number is a positive integer no greater than one billion. The input is terminated by a line containing two zeros. This last line is not a test case and should not be processed.

    Output

    For each test case, output a line containing one integer, the number of CDs that Jack and Jill both own.

    Sample Input 1Sample Output 1
    3 3
    1
    2
    3
    1
    2
    4
    0 0
    
    2

    题意

    计算两个人的CD的序号有多少个相同的

    代码

    #include<bits/stdc++.h>
    using namespace std;
    #define LL long long
    const int maxn = 10010000;
    LL n, m;
    LL a[maxn];
    int main() {
        while(cin >> n >> m) {
            if(n == m && n == 0)
                break;
            LL x, cnt = 0;
            memset(a, 0, sizeof(a));
            for(LL i = 0; i < n; i++) {
                cin >> x;
                a[x] = 1;
            }
            for(LL i = 0; i < m; i++) {
                cin >> x;
                if(a[x])
                    cnt++;
            }
            cout << cnt << endl;
        }
    }
  • 相关阅读:
    Apache Cassandra 4.0新特性介绍
    NoSQLBench压测工具入门教程
    赵洋:深入了解Materialized View
    PHP与ECMAScript_1_变量与常量
    HTTP_5_通信数据转发程序:代理、网关、隧道
    HTTP_4_返回结果的HTTP状态码
    HTTP_3_HTTP报文
    HTTP_2_HTTP协议概要
    HTTP_1_Web及网络基础
    一个完整的产品设计流程——家庭安全管家
  • 原文地址:https://www.cnblogs.com/zhien-aa/p/6284077.html
Copyright © 2011-2022 走看看