题解 | #求长方体表面积#

判断元素是否出现

http://www.nowcoder.com/practice/0787459e92bc4360ba48b094b7f21577

#include<bits/stdc++.h>
#include<map>
using namespace std;
int main() {
    //write your code here......
    map<int,string>ma;
    map<int,string>::iterator it;
    int m,n,x;
    cin>>n>>m;
    //导入map数据结构用insert
    while(n--){
        cin>>x;
        ma.insert(pair<int,string>(x,"yes"));
    }
    while(m--){
        cin>>x;
        it = ma.find(x);//查找map中是否有x键的元素,有则返回该元素位置,没有则返回map.end()
        if (it == ma.end()) cout<<"no"<<endl;
//         else cout<<it->second<<endl;//也可以
        else cout<<"yes"<<endl;
        
    }
    

    return 0;
}
全部评论

相关推荐

牛客845590724号:单学校就够拷打了
点赞 评论 收藏
分享
评论
6
1
分享

创作者周榜

更多
牛客网
牛客企业服务