今天开始学STL,这是书上的一道例题,主要是用了sort函数和lower_bound函数,挺容易理解的。

lower_bound的作用是查找“大于或等于x的第一个位置”。

需要注意的是,不要忘记algorithm头文件。

使用STL真的方便了不少啊!

Where is the Marble?,UVa 10474

#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = ; int main() {
int n,q,x,a[maxn],kase=;
while(scanf("%d%d",&n,&q)==&&n){
printf("CASE# %d:\n",++kase);
for(int i=;i<n;i++) scanf("%d",&a[i]);
sort(a,a+n);//排序
while(q--){
scanf("%d",&x);
int p=lower_bound(a,a+n,x)-a;//在已排序数组a中寻找x
if(a[p]==x) printf("%d found at %d\n",x,p+);
else printf("%d not found\n",x);
}
}
return ;
}

最新文章

  1. Can&#39;t use Subversion command line client: svn Probably the path to Subversion executable is wrong. Fix it.
  2. VS2012 InstallShield2013LimitedEdition激活
  3. $(&quot;#id&quot;).val()取值textarea是&quot;&quot;
  4. UVA 11827 Maximum GCD
  5. oracle11g rac asm存储数据迁移
  6. iOS中生成并导入基于Swift编程语言的Framework
  7. Swift -- 官方文档Swift-Guides的学习笔记
  8. C语言中结构体的初始化
  9. Ubuntu环境下Hadoop1.2.1, HBase0.94.25, nutch2.2.1各个配置文件一览
  10. 广播接收者 BroadcastReceiver 示例-2
  11. jsp中包含JAVA代码
  12. effective c++ 条款5 c++ 默默实现的函数
  13. 【Python 函数对象 命名空间与作用域 闭包函数 装饰器 迭代器 内置函数】
  14. BZOJ_4378_[POI2015]Logistyka_树状数组
  15. LaTeX教程与下载
  16. CodeIgniter中使用base_url()时显示http://::1/ci/
  17. wpf 的依赖属性只能在loaded 事件之后才能取到
  18. Redis之序列化POJO
  19. Android pm 命令详解
  20. Poi中getPhysicalNumberOfCells 与 getLastCellNum的差异

热门文章

  1. 再次挑戰UCOSII内核源码
  2. 关于keildownload键变为灰色不能使用的问题
  3. Oooooooo AAAAE 【网络流最小点权覆盖】
  4. BandingList 泛型集合数据绑定
  5. 【环境搭建】Angular (含Hello World)
  6. 红米K20PRO解锁Bootloader权限并刷入recovery
  7. 灾备系统 RTO与RPO
  8. docker CMD 和 ENTRYPOINT 区别
  9. Spring实战(十一) 在Spring XML中配置AOP
  10. ASP.NET Core MVC里面Razor如何获取URL参数