zoukankan      html  css  js  c++  java
  • Linear Search Aizu

    Search I

    You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S.

    Input

    In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers are given.

    Output

    Print C in a line.

    Constraints

    n ≤ 10000
    q ≤ 500
    0 ≤ an element in S ≤ 109
    0 ≤ an element in T ≤ 109

    Sample Input 1

    5
    1 2 3 4 5
    3
    3 4 1

    Sample Output 1

    3

    Sample Input 2

    3
    3 1 2
    1
    5

    Sample Output 2

    0

    Sample Input 3

    5
    1 1 2 2 3
    2
    1 2

    Sample Output 3

    2

    code

    /*
                                    ^....0
                                   ^ .1 ^1^
                                   ..     01
                                  1.^     1.0
                                 ^ 1  ^    ^0.1
                                 1 ^        ^..^
                                 0.           ^ 0^
                                 .0            1 .^
                                 .1             ^0 .........001^
                                 .1               1. .111100....01^
                                 00             ^   11^        ^1. .1^
                                 1.^                              ^0  0^
                                   .^                                 ^0..1
                                   .1                                   1..^
                                 1 .0                                     ^  ^
                                  00.                                     ^^0.^
                                  ^ 0                                     ^^110.^
                              0   0 ^                                     ^^^10.01
                       ^^     10  1 1                                      ^^^1110.1
                       01     10  1.1                                      ^^^1111110
                       010    01  ^^                                        ^^^1111^1.^           ^^^
                       10  10^ 0^ 1                                            ^^111^^^0.1^       1....^
                        11     0                                               ^^11^^^ 0..  ....1^   ^ ^
                        1.     0^                                               ^11^^^ ^ 1 111^     ^ 0.
                       10   00 11                                               ^^^^^   1 0           1.
                       0^  ^0  ^0                                                ^^^^    0            0.
                       0^  1.0  .^                                               ^^^^    1 1          .0
                       ^.^  ^^  0^                             ^1                ^^^^     0.         ^.1
                       1 ^      11                             1.                ^^^     ^ ^        ..^
                      ^..^      ^1                             ^.^               ^^^       .0       ^.0
                      0..^      ^0                              01               ^^^       ..      0..^
                     1 ..        .1                             ^.^              ^^^       1 ^  ^0001
                    ^  1.        00                              0.             ^^^        ^.0 ^.1
                    . 0^.        ^.^                             ^.^            ^^^         ..0.0
                   1 .^^.         .^                  1001        ^^            ^^^         . 1^
                   . ^ ^.         11                0.    1         ^           ^^          0.
                    0  ^.          0              ^0       1                   ^^^          0.
                  0.^  1.          0^             0       .1                   ^^^          ..
                  .1   1.          00            .        .1                  ^^^           ..
                 1      1.         ^.           0         .^                  ^^            ..
                 0.     1.          .^          .         0                                  .
                 .1     1.          01          .        .                                 ^ 0
                ^.^     00          ^0          1.       ^                                 1 1
                .0      00           .            ^^^^^^                                   .
                .^      00           01                                                    ..
               1.       00           10                                                   1 ^
              ^.1       00           ^.                                            ^^^    .1
              ..        00            .1                                        1..01    ..
             1.1         00           1.                                       ..^      10
            ^ 1^         00           ^.1                                      0 1      1
            .1           00            00                                       ^  1   ^
             .           00            ^.^                                        10^  ^^
           1.1           00             00                                              10^
           ..^           1.             ^.                                               1.
          0 1            ^.              00                 00                            .^
            ^            ^.              ^ 1                00   ^0000^     ^               01
         1 0             ^.               00.0^              ^00000   1.00.1              11
         . 1              0               1^^0.01                      ^^^                01
          .^              ^                1   1^^                                       ^.^
        1 1                                                                              0.
        ..                                                                              1 ^
         1                                                                               1
       ^ ^                                                                             .0
       1                                                                             ^ 1
       ..                                                          1.1            ^0.0
      ^ 0                                                           1..01^^100000..0^
      1 1                                                            ^ 1 ^^1111^ ^^
      0 ^                                                             ^ 1      1000^
      .1                                                               ^.^     .   00
      ..                                                                1.1    0.   0
      1.                                                                  .    1.   .^
      1.                                                                 1    1.   ^0
     ^ .                                                                 ^.1 00    01
     ^.0                                                                  001.     .^
     */
    // Virtual_Judge —— Linear Search Aizu - ALDS1_4_A.cpp created by VB_KoKing on 2019-05-01:18.
    /* Procedural objectives:
    
     Variables required by the program:
    
     Procedural thinking:
    
     Functions required by the program:
    
    */
    /* My dear Max said:
    "I like you,
    So the first bunch of sunshine I saw in the morning is you,
    The first hurricane that passed through your ear is you,
    The first star you see is also you.
    The world I see is all your shadow."
    
    FIGHTING FOR OUR FUTURE!!!
    */
    #include <iostream>
    
    using namespace std;
    
    bool search(int A[], int n, int key) {
        int i = 0;
        A[n] = key;
        while (A[i] != key) i++;
        return i != n;
    }
    
    int main() {
        int n, q, key, sum = 0, A[10007];
        cin >> n;
        for (int i = 0; i < n; i++)
            cin >> A[i];
        cin >> q;
        for (int i = 0; i < q; i++) {
            cin >> key;
            if (search(A, n, key)) sum++;
        }
        cout << sum << endl;
        return 0;
    }
    
  • 相关阅读:
    KubeCon 2020 演讲集锦|《阿里巴巴云原生技术与实践 13 讲》开放下载
    突围数字化转型,让特步同比增长24.8%的全渠道中台
    阿里云飞天大数据产品价值解读——《一站式高质量搜索开放搜索》
    高德AR驾车导航解决方案
    我在阿里写代码学会的六件事
    送外卖也要“黑科技”?阿里移动感知技术应用揭秘
    阿里云机器学习怎么玩?这本新手入门指南揭秘了!
    用户自定义类型03 零基础入门学习Delphi33
    用户自定义类型03 零基础入门学习Delphi33
    用户自定义类型01 零基础入门学习Delphi31
  • 原文地址:https://www.cnblogs.com/AlexKing007/p/12338375.html
Copyright © 2011-2022 走看看