Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main() {
- ifstream fin("binsearch.in");
- ofstream fout("binsearch.out");
- int n, m;
- cin >> n;//array size
- int* a = new int[n];
- for (int i = 0; i < n; ++i)
- cin >> a[i];
- cin >> m;//requests count
- int* rq = new int[m];
- for (int i = 0; i < m; ++i)
- cin >> rq[i]; //requests
- int k = 0, count_rq1 = 0, count_rq2 = 0, h = 0;
- for (int i = 0; i < n, k < m; ++i)
- {
- //if (k == m) break;//if all requests done end "for"
- int x = rq[k];//current request
- if (x != a[i])
- {
- int error = -1;
- cout << error << " " << error << endl;
- ++k;
- }
- if (x == a[i])//if found request in array
- {
- count_rq2 = i;
- ++h;
- if (a[i + 1] != x)//if next element != request than will find a new request
- {
- ++k;
- h -= 1;
- count_rq1 = count_rq2 - h + 1;
- count_rq2 += 1;
- cout << count_rq1 << " " << count_rq2 << endl;
- h = 0;
- }
- }
- }
- delete(a);
- delete(rq);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement