P8833 [传智杯 #3 决赛] 课程

P8833 [传智杯 #3 决赛] 课程_第1张图片

输入输出样例

输入 #1

5 5
1 2 3 4 5
1 3 4 5 6

输出 #1

4
#include 
#define endl '\n'
#define int long long
using namespace std;
constexpr int N = 1e5, inf = 0x3f3f3f3f;
bool vis[N];
void solve()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        vis[a] = true;
    }
    int cnt = 0;
    for (int i = 0; i < m; i++)
    {
        int a;
        cin >> a;
        if (vis[a])
        {
            cnt++;
        }
    }
    cout << cnt << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    solve();

    return 0;
}

你可能感兴趣的:(ou_fan的学习记录,算法,c++,图论)