题目描述
现有N个大理石,每个大理石上写了一个非负整数、首先把各数从小到大排序然后回答Q个问题。每个问题问是否有一个大理石写着某个整数x,如果是,还要回答哪个大理石上写着x。排序后的大理石从左到右编号为1~N。
输入
第一行2个整数n、m,n表示大理石的数量,m表示有几个问题
第二行有n个数字,表示大理石上的数字
第三行有m个数字,表示问的数字x
输出
1个问题输出一行
比如发现数字5在第4块大理石上,则输出
CASE# 1:5 found at 4
比如数字2,所有大理石上都没有发现,则输出
CASE# 2:2 not found
样例
样例1
输入
4 1
2 3 5 1
5
输出
5 found at 4
样例2
输入
5 2
1 3 3 3 1
2 3
输出
2 not found
3 found at 3
数据规模
大理石数量不超过10000,每个数字不超过int范围,问题不超过1000
题解
这道题非常easy,直接上代码
#include<bits/stdc++.h>
using namespace std;
vector<int>win;
int n,m,x,l;
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>l;
win.push_back(l);
}
sort(win.begin(),win.end());
while(m--)
{
cin>>x;
bool k=true;
for(int i=0;i<win.size();i++)
{
if(win[i]==x)
{
k=false;
cout<<x<<' '<<"found at "<<i+1<<endl;
break;
}
}
if(k)
{
cout<<x<<' '<<"not found"<<endl;
}
}
return 0;
}