您的位置:首页 > 其它

UVa 10474: Where is the Marble

2017-01-08 14:55 344 查看
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
int N, Q;
int case_num = 1;

while(cin >> N >> Q)
{
if (N == 0 && Q == 0)
return 0;

if(N <= 0 || N > 10000 || Q <= 0 || Q > 10000)
return 1;

int *marbel = new int[N + 1];
int *query = new int[Q];

for(int i = 1; i <= N; i++)
{
cin >> marbel[i];

if(marbel[i] < 0 || marbel[i] > 10000)
return 1;
}

for(int j = 0; j < Q; j++)
{
cin >> query[j];

if(query[j] < 0 || query[j] > 10000)
return 1;
}

sort(marbel + 1, marbel + N + 1);

cout << "CASE# " << case_num << ":" << endl;

for(int k = 0; k < Q; k++)
{
int p = lower_bound(marbel + 1, marbel + 1 + N, query[k]) -  marbel;
if(marbel[p] == query[k])
cout << query[k] << " found at " << p << endl;
else
cout << query[k] << " not found" << endl;
}

case_num++;

delete(marbel);
delete(query);

if(case_num >= 65)
return 0;
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uva 10474