Loading [MathJax]/extensions/TeX/AMSsymbols.js

2016年5月5日 星期四

uva 10474 Where is the Marble?

題目來源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1415

程式碼:


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
int N,Q,a[10000],x,ptr,times = 1;
while(scanf("%d %d",&N,&Q)==2 && (N || Q)){
for(int i = 0;i<N;i++)
scanf("%d",&a[i]);
sort(a,a+N);//排序
printf("CASE# %d:\n",times++);
while(Q--){
scanf("%d",&x);
ptr = lower_bound(a,a+N,x)-a;
//如果有找到
if(a[ptr]==x) printf("%d found at %d\n",x,ptr+1);
//如果沒找到
else printf("%d not found\n",x);
}
}
}
view raw 10474.cpp hosted with ❤ by GitHub

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。