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

题很简单: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. leetcode日记 Product of Array Except Self

    Given an array of n integers where n > 1, nums, return an array output such that output[i] is equ ...

  2. VMware下利用ubuntu13.04建立嵌入式开发环境之四

    二.telnet.SSH服务器安装与配置 1.telnet 1.1 安装服务器:apt-get install xinetd telnetd 1.2 安装openbsd-inetd:apt-get i ...

  3. JAVA开发相关

    JAVA开发相关1. IntelliJ IDEA开发工具熟练使用2. Maven3. Spring框架(IoC.AOP) 1)数据库相关MyBatis 2)数据库连接池 3)事务.多数据源.跨数据库分 ...

  4. 关于ios “<null>”的异常处理

    在iOS开发过程中经常需要与服务器进行数据通讯,但是在数据接通过程中会出现:null "<null>"等问题导致莫名其妙的崩溃. 相信你一定会写各种判断来处理这些异常, ...

  5. MVC3之ViewData与ViewBag

    首先先用代码来说话: ViewData: public ActionResult Index() { List<string> colors = new List<string> ...

  6. UART接口基本知识

    Universal asynchronous transciever即同一异步收发器,也就是我们平时所说的串口,是一种最简单,最基本的通信接口. 通信接口按照不同的标准有不同的分类,常见的有同步或异步 ...

  7. 了解JavaWeb,一篇就够

    把HTML.CSS.JSP.JS.JavaScript,JQuery,STRUTS,String,MVC,DOM 柔和起来,贯穿成一篇完整的内容,让读者明白JavaWeb的前前后后. 从Servlet ...

  8. Mysql 根据时间戳、时间按年月日分组统计

    create_time时间格式 SELECT DATE_FORMAT(create_time,'%Y%u') weeks,COUNT(id) COUNT FROM role GROUP BY week ...

  9. UE4 VR GUI实现 参考(UMG AND VR)

    Note:4.13以后版本VR UI采用 WidgetComponent + WidgetInteractionComponent可轻松实现交互 Blueprint Demo: https://for ...

  10. C语言复杂声明-void (*signal(int sig, void (*handler)(int)))(int);

    问题提出 请分析此声明:void (*signal(int sig, void (*handler)(int)))(int); 求解过程 在对上面的例子作分析之前,我们需要了解C语言的声明优先级,&l ...