跳到正文

题解

题解:P15799 [GESP202603 五级] 找数

wusheng_约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年3月15日
收录
2026年3月18日
更新
2026年9月11日
篇幅
约 1 分钟
题目
P15799

版本

  1. v1当前

题目传送门

思路

可以用 unordered_set 存储数组 AA 的元素,然后判断数组 BB 的元素有没有出现过第二次。

代码

代码(注释精读版):

C++
#include"bits/stdc++.h"
using namespace std;

int n,m,cnt;
unordered_set<int>st;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		st.insert(x);//加入
	}
	for(int i=1;i<=m;i++){
		int y;
		scanf("%d",&y);
		if(st.count(y))cnt++;//判断是否已经出现过
	}
	printf("%d\n",cnt);
	return 0;
}
原文
存档评论6 条抓取于