forked from siddharth25pandey/CPP-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Where_is_the_Marble.cpp
69 lines (55 loc) · 1.34 KB
/
Where_is_the_Marble.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// git-book link : https://jordy-bro.gitbook.io/golok/task-6-solutions#where-is-the-marble
// problem statement : https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1415
// author : Chinmay Lohani
// Date: 09.10.2022
#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;
int binarySearch(vector<ull> &arr, int l, int r, int x)
{
for(int i = l ; i <= r ; i++)
{
if(arr[i] == x)
{
return i;
}
}
return 0;
}
int main()
{
ull cnt = 0;
while(true)
{
ull n , q;
cin >> n >> q;
if(n == 0 && q == 0)
{
break;
}
cnt++;
cout << "CASE# " << cnt << ":\n";
vector<ull> v(n,0);
for(int i = 0 ; i < n ; i++)
{
cin >> v[i];
// cout << v[i] << " " ;
}
sort(v.begin(), v.end());
while(q--)
{
int tmp;
cin >> tmp;
int pos = binarySearch(v , 0 , n-1 , tmp);
if(v[pos] == tmp)
{
cout << tmp << " found at " << pos+1 << '\n';
}
else
{
cout << tmp << " not found\n";
}
}
}
return 0;
}