zoukankan      html  css  js  c++  java
  • NYOJ 86 找球号(一)(<set>)

    找球号(一)

    时间限制:3000 ms  |           内存限制:65535 KB
    难度:3
     
    描述
    在某一国度里流行着一种游戏。游戏规则为:在一堆球中,每个球上都有一个整数编号i(0<=i<=100000000),编号可重复,现在说一个随机整数k(0<=k<=100000100),判断编号为k的球是否在这堆球中(存在为"YES",否则为"NO"),先答出者为胜。现在有一个人想玩玩这个游戏,但他又很懒。他希望你能帮助他取得胜利。
     
    输入
    第一行有两个整数m,n(0<=n<=100000,0<=m<=1000000);m表示这堆球里有m个球,n表示这个游戏进行n次。 接下来输入m+n个整数,前m个分别表示这m个球的编号i,后n个分别表示每次游戏中的随机整数k
    输出
    输出"YES"或"NO"
    样例输入
    6 4
    23 34 46 768 343 343
    2 4 23 343
    
    样例输出
    NO
    NO
    YES
    YES
    资料参考:<set> find():http://www.cplusplus.com/reference/set/set/find/
     1  
     2 #include<iostream>
     3 #include<set>
     4  using namespace std;
     5  int main()
     6  {
     7      int n,m,b[100010];
     8      int i,a;
     9      set< int >myset;
    10      cin>>n>>m;
    11      while(n--)
    12      {
    13      cin>>a;
    14      myset.insert(a);
    15      }
    16      for(i=0;i<m;i++)
    17      cin>>b[i];
    18      for(i=0;i<m;i++)
    19      {
    20      if(myset.find(b[i])!=myset.end())
    21      //Searches the container for an element equivalent to val and returns an iterator to it if found,
    22      //otherwise it returns an iterator to set::end.
    23      cout<<"YES"<<endl;
    24      else cout<<"NO"<<endl;
    25      }
    26  return 0;
    27  }
    28         
    View Code
  • 相关阅读:
    2015第18周四
    2015第18周三程序员能力
    2015第18周二
    2015第18周一
    2015第17周日活在当下
    2015第17周六去除表中某字段重复记录
    2015第17周五
    2015第17周四
    Mac OS X Yosemite安装Hadoop 2.6记录
    GLEW_ERROR_NO_GL_VERSION的解决方法
  • 原文地址:https://www.cnblogs.com/luoshuihanbing/p/3288888.html
Copyright © 2011-2022 走看看