题意:给你一组数,再给几个数问是否在一组数中。

题很简单:STL入门。

没用到STL。

#include<iostream>
#include<cstdio>
#include<algorithm> using namespace std;
int a[];
int main()
{
int ncase = ;
//freopen("in.txt","r",stdin);
int n,m;
while(scanf("%d%d",&n,&m) != EOF){
if(n == && m == )
break;
printf("CASE# %d:\n",ncase++);
for(int i = ;i <= n; i++)
scanf("%d",&a[i]);
sort(a+,a+n+);
for(int i = ;i <= m; i++){
int ans;
scanf("%d",&ans);
int flag = false;
int j;
for(j = ;j <= n; j++)
if(a[j] == ans){
flag = true;
break;
}
if(flag)
printf("%d found at %d\n",ans,j);
else
printf("%d not found\n",ans);
}
}
return ;
}

STL。

#include<iostream>
#include<cstdio>
#include<algorithm> using namespace std;
int a[];
int main()
{
int ncase = ;
//freopen("in.txt","r",stdin);
int n,m;
while(scanf("%d%d",&n,&m) != EOF){
if(n == && m == )
break;
printf("CASE# %d:\n",ncase++);
for(int i = ;i <= n; i++)
scanf("%d",&a[i]);
sort(a+,a+n+);
for(int i = ;i <= m; i++){
int ans;
scanf("%d",&ans);
int flag;
// for(j = 1;j <= n; j++)
// if(a[j] == ans){
// flag = true;
// break;
// }
flag = lower_bound(a+,a+n+,ans) - a;  //很容易看出怎么操作的
if(a[flag] == ans)
printf("%d found at %d\n",ans,flag);
else
printf("%d not found\n",ans);
}
}
return ;
}

UVA 10474的更多相关文章

  1. UVA.10474 Where is the Marble ( 排序 二分查找 )

    UVA.10474 Where is the Marble ( 排序 二分查找 ) 题意分析 大水题一道.排序好找到第一个目标数字的位置,返回其下标即可.暴力可过,强行写了一发BS,发现错误百出.应了 ...

  2. 大理石在哪里UVa 10474

    我自己写的代码 #include<iostream>#include<algorithm>using namespace std;int main(){    int N,a[ ...

  3. UVA 10474 大理石在哪 lower_bound

    题意:找输入的数在排完序之后的位置. 主要是lower_bound 函数的使用.它的作用是查找大于或者等于x的第一个位置. #include<cstdio> #include<alg ...

  4. 大理石在哪?(Where is the Marble?,UVa 10474)

    参考:ACM紫书 第五章 P108 [排序与检索] 下面的代码中有些 提示性输出,想Ac 需删除提示性输出语句,读者自行修改. #include <cstdio> #include < ...

  5. UVa 10474 Where is the Marble

    题意:给出一列数,先排序,再查找学习了sort函数,lower_bound函数sort:可以给任意对象排序(包括自己定义的)(前提是定义好了‘<’运算符)lower_bound:查找大于或者等于 ...

  6. uva 10474 Where is the Marble? 计数排序

    题目给出一系列数字,然后问哪个数字是从小到大排在第几的,重复出现算第一个. 数据范围为10000,不大,完全可以暴力,sort不会超时. 但是由于以前做比赛时也遇到这种题目,没注意看数据范围,然后暴力 ...

  7. UVA 10474 - Where is the Marble?--vector

    https://vjudge.net/problem/UVA-10474 https://blog.csdn.net/xiyaozhe/article/details/81081344 简单用法 so ...

  8. UVA 10474 (13.08.04)

     Where is the Marble?  Raju and Meena love to play with Marbles. They have got a lotof marbles with ...

  9. 大理石在哪儿 (Where is the Marble?,UVa 10474)

    题目描述:算法竞赛入门经典例题5-1 #include <iostream> #include <algorithm> using namespace std; ; int m ...

随机推荐

  1. jquery mobile 输入框无边框

    现在移动开发为主流的时代,少不了使用jquery mobile.但是偶然应项目要求需要把input输入框做成无边框的,不是特别容易的事,网上找了很多都没有一种靠谱的解决方案,只能自食其力了. < ...

  2. html canvas 骰子1

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. 使用composer安装项目依赖

    Composer 是 PHP 的一个依赖管理工具.它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们 下载并安装composer composer官方文档有好几种安装方法,此处只介绍我实验过 ...

  4. 从angularJS改道Vue.js,趟过第一个坑!

    vue采用 new vue()初始化,显然vue内部没有类似jquery ready函数的机制,在文档加载完成后再执行初始化. 今天新学习vue,由于vue采用es5的特殊机制更新UI,我不确定ipa ...

  5. java 调用 sql server存储过程

    Transact-SQL中的存储过程,非常类似于Java语言中的方法,它可以重复调用.当存储过程执行一次后,可以将语句缓存中,这样下次执行的时候直接使用缓存中的语句.这样就可以提高存储过程的性能. Ø ...

  6. 第7章 LED将为我闪烁:控制发光二极管

    所谓I/O内存是通过各种接口连接到主机的硬件在主机内存的映射.LED驱动还提供了两种交互方式:命令和读写设备文件. 创建设备文件的步骤: 第1步:使用cdev_init函数初始化cdev 第2步:指定 ...

  7. BZOJ 3176 Sort

    先一遍reverse+逆序对个数. 要开long long啊. #include<iostream> #include<cstdio> #include<cstring& ...

  8. 盲注----基于布尔的SQL盲注

    构造逻辑判断常用字符串截取函数http://www.cnblogs.com/yyccww/p/6054569.html常用函数left(a,b)  从左侧截取a的前b位right(a,b)  从右侧截 ...

  9. BZOJ 1858 线段树

    标记会重叠需要判断. #include <bits/stdc++.h> using namespace std; inline int Max(int x,int y) {return x ...

  10. springMvc 报错

    org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.util.Ar ...