排序检索-10474 - Where is the Marble?
来源:互联网 发布:yoga lenovo 知乎 编辑:程序博客网 时间:2024/05/16 06:53
题目大意:给出一组数据,按升序排列。给出一个数字,查询它在数组中的位置,并输出,不存在,则输出“no found”
解题过程:WA一次,没有考虑到给出的数字大于所有数据的情况
正确代码:
# include <cstdio># include <cstdlib># include <ctime># include <cmath># include <iostream># include <fstream># include <cstring># include <string>//*#define fin cin#define fout cout//*/using namespace std;/*ifstream fin("in.txt");ofstream fout("out.txt");//*/int cmp(const void*a,const void*b){return *(int*)a-*(int*)b;}int main(){int n,q; int qu;fin>>n>>q;int time=0;while(n!=0||q!=0){time++;int * marble=new int[n];for(int i=0;i<n;i++){fin>>marble[i];}qsort(marble,n,sizeof(marble[0]),cmp);fout<<"CASE# "<<time<<":"<<endl;while(q){q--;fin>>qu;for(int i=0;i<n;i++){if(marble[i]>qu){fout<<qu<<" not found"<<endl;break;}else if(marble[i]==qu){fout<<qu<<" found at "<<i+1<<endl;break;}}if(marble[n-1]<qu) fout<<qu<<" not found"<<endl;}fin>>n>>q;}return 0; }
0 0
- 排序检索-10474 - Where is the Marble?
- 排序检索C - Where is the Marble?
- UVA 10474 (暑假-排序、检索 -C - Where is the Marble?)
- UVa 10474 - Where is the Marble?【排序和检索】
- 10474 - 大理石在哪儿Where is the Marble?(排序+检索)
- Uva 10474 Where is the Marble?(排序与检索)
- 排序/查找 10474 - Where is the Marble?
- 经典第五章例5.1 UVa 10474 Where is the Marble?(排序与检索)
- UVa 10474 Where is the Marble? 【STL】【排序与检索-sort和lower_bound】
- 10474--Where is the Marble
- 10474 - Where is the Marble?
- 10474 - Where is the Marble?
- 10474 - Where is the Marble?
- 10474 - Where is the Marble?
- 10474Where is the Marble?
- 10474 - Where is the Marble?
- 10474 - Where is the Marble?
- 10474 - Where is the Marble
- java面试准备-day03-并发包类
- 安卓的通信机制
- POJ 2142 The Balance .
- RDD与DataFrame
- 转:虚幻4引擎3d化UI教程
- 排序检索-10474 - Where is the Marble?
- 让Dev C++支持C++11
- 2092 整数解
- Swift-Swift初体验
- 小娜老师的讲义-Docker基础知识-容器(一)
- windows7 64bite环境安装theano
- linux学习第七课--文件夹属性
- Java中对象的初始化和回收
- 校园的一角