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

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

参考:ACM紫书 第五章 P108 【排序与检索】

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

下面的代码中有些 提示性输出,想Ac 需删除提示性输出语句,读者自行修改。

#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 10000; int main(void)
{
int n,q,numarr[maxn],i,x,p,Case=0;
while(scanf("%d%d",&n,&q)==2 && n)
{
printf("CASE# %d:\n",++Case);
for(i=0; i<n; i++)
{
scanf("%d",&numarr[i]);
}
sort(numarr,numarr+n);
while(q--)
{
scanf("%d",&x); printf("%d--%p\n",*numarr,numarr);
printf("%d--%p\n",*lower_bound(numarr,numarr+n,x),lower_bound(numarr,numarr+n,x)); p=lower_bound(numarr,numarr+n,x)- numarr;
printf("p = %d\n",p);
if(numarr[p]==x)printf("%d found at %d\n",x,p+1);
else printf("%d not found\n",x);
}
}
return 0;
}

  

上一篇:我决定!墙裂推荐高清无码Python电子书(文中福利)


下一篇:oracle 空表无法导出