天苜仙影


私信TA

用户名:2714425647

访问量:1832

签 名:

QID:TG92ZTA2

等  级
排  名 268
经  验 5671
参赛次数 9
文章发表 31
年  龄 18
在职情况 学生
学  校 中国地质大学(武汉)
专  业

  自我简介:

学过C语言,欢迎大家加我QQ交流

解题思路:

注意事项:

看到很多大佬都是使用set来写的,但是我觉得这道题没必要使用set,因为set相对于multiset,有输入中不能有重复元素的限制,导致set元素的插入有可能失败

(仅仅代表个人看法)

参考代码:

#include<iostream>

#include<set>

using namespace std;

int main(void)

{

int i;

int n,temp,m;

while(cin>>n&&n!=-1)

{

multiset<int>st;

multiset<int>::iterator j;

for(i=0;i<n;i++)

{

cin>>temp;

st.insert(temp);

}

cin>>m;

for(i=0;i<m;i++)

{

cin>>temp;

if(st.find(temp)==st.end())

{

cout<<"NO"<<endl;

}

else

{

cout<<"YES"<<endl;

}

}


return 0;

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区