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

题很简单: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. LLDB, iOS调试器

    breakpoint set -s "" breakpoint set    -M <method> ( --method <method> )    -S ...

  2. Python错误和异常学习

    一:错误解释 1.语法错误:代码不符合解释器或者编译器语法 2.逻辑错误:不完整或者不合法输入或者计算出现问题 代码运行前的语法或者逻辑错误,语法错误在执行前修改,逻辑错误无法修改 二:异常 执行过程 ...

  3. 例子:Basic Lens sample

    本例演示了如何自己扩展一个Camera Lens. 1. UI界面是一个MediaViewer <controls:MediaViewer x:Name="MediaViewer&qu ...

  4. Python的平凡之路(21)

    上节内容回顾:1.请求周期url> 路由 > 函数或类 > 返回字符串或者模板语言?Form表单提交:    提交 -> url > 函数或类中的方法     - ... ...

  5. 实用工具【SqlPrompt】 【Subline】 【XMind】 【PhotoShop】 【TakeColor】 【Q+】本次只讨论SqlPrompt

    SqlPrompt[Sqlserver智能提示插件] 1.SqlPrompt可实现sql智能提示,并且会自动关键字大写,如select * from 表名[表名包含的字符],如果实在不知道表名可以按c ...

  6. JS总结 循环 退出循环 函数

    while循环 while(条件){条件成立就执行的代码} *一般条件变量需要递增,否则会进入死循环(无限循环),浏览器会崩溃甚至电脑死机 例如,逐行输出1-100的数字 var i = 1; whi ...

  7. django常见小问题收集(转)

    1.当我把 DEBUG = True设为False的时候运行 python manage.py runserver 的时候 报错 : CommandError: You must set settin ...

  8. thinkPHP(待更新)

    一些函数 1.  set_include_path().get_include_path() .PATH_SEPARATOR 设置php加载的路径 2.  register_shutdown_func ...

  9. nexus7 一代 手动刷4.4.4

    跟上一篇类似,但是中间出了点问题,提示说command write 出错,最后解决方法是电脑上换了个usb口插入....

  10. shell 中变量前"?"的作用

    example: if ($?USER == 0 || $?prompt == 0)   then       ....     if ( $?DS_HOME != 0 ) then if ( ${? ...