UVA10474 Where is the Marble?
来源:互联网 发布:淘宝模特夏 编辑:程序博客网 时间:2024/05/16 01:01
问题链接:UVA10474 Where is the Marble?。
题意简述:输入n个整数,代表大理石编号;再输入q个数(编号),问是否有这个编号的大理石,位置在哪里?
这个问题用C++语言编写程序,主要是为了练习使用STL的功能。
程序中,使用了算法库(algorithm)中的两个函数;使用sort()函数用于对数据排序,该函数的参数比C语言的同类函数简单,程序更加易于书写;使用函数lower_bound()查找元素,简单方便。
AC的C++语言程序如下:
/* UVA10474 Where is the Marble? */#include <iostream>#include <algorithm>using namespace std;#define MAXN 11000int marble[MAXN];int main(){ int n, q, caseno=0, val; while(scanf("%d%d", &n, &q) != EOF) { if(n == 0 && q == 0) break; for(int i=0; i<n; i++) scanf("%d", &marble[i]); sort(marble, marble + n); printf("CASE# %d:\n", ++caseno); while(q--) { scanf("%d", &val); int no = lower_bound(marble, marble + n, val) - marble; if(marble[no] == val) printf("%d found at %d\n", val, no + 1); else printf("%d not found\n", val); } } return 0;}
1 0
- uva10474 - Where is the Marble?
- UVa10474 Where is the Marble?
- UVA10474-Where is the Marble?
- UVA10474 Where is the Marble?
- uva10474 - Where is the Marble?
- uva10474 Where is the Marble?
- uva10474 - Where is the Marble?
- UVA10474 Where is the Marble?
- UVA10474 Where is the Marble?
- UVA10474 Where is the Marble?
- UVa10474-Where is the Marble?
- uva10474大理石在哪儿where is the marble?
- UVA10474 where is the Marble? STL初步
- Uva10474——Where is the Marble?
- 5-1 UVa10474 Where is the Marble?
- UVA10474-5.1-Where is the Marble?
- UVA10474 Where is the Marble?(二分查找,STL-lower_bound)
- Where is the Marble
- TCP的拥塞控制 (Tahoe Reno NewReno SACK)
- 资源链接
- ue4 Android打包示例
- Hibernate的总结
- 数据结构实验之栈 后缀式求值(sdut oj2133)
- UVA10474 Where is the Marble?
- CodeForces 109B Lucky Probability
- POJ 1682 Clans on the Three Gorges
- Java继承的限制
- 【POJ】-1287-Networking(最小生成树)
- Apache Commons工具集简介
- poj 2386 同 nyoj 27 dfs
- POJ-1383 Labyrinth(迷宫的最长距离)
- android webview: 视频全屏播放按返回页面被放大的问题