其他分享
首页 > 其他分享> > 大理石问题(STL)

大理石问题(STL)

作者:互联网

如何从N个大理石中找到特定数,先输入N,再输入Q,输入大理石的编号,再输入问题;

for example:

4 1

2 3 5 1

5

 

#include<cstdio>
#include<algorithm>

using namespace std;
const int maxn = 10000;
int a[maxn];

int main()
{
int n, q, x;
int kase = 0;
while(scanf("%d%d", &n, &q) == 2 && n)
{
printf("#case %d: \n", ++kase);
for(int i = 0 ; i < n ; i++)
{
scanf("%d", &a[i]);
}
sort(a, a + n);
while(q--)
{
scanf("%d", &x);
int p = lower_bound(a, a + n, x) - a;
if(a[p] == x)
{
printf("%d found at %d", x, p + 1 );
}
else
printf("%d not found", x);
}
}
return 0;
}

标签:STL,大理石,scanf,问题,int,maxn,printf,kase,输入
来源: https://www.cnblogs.com/zxc666/p/zxcniub.html