Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream fin("date.in");
- int a[100], n, b[100], m, k;
- void ctr() {
- fin >> n >> m >> k;
- for(int i = 0; i < n; ++i)
- {
- fin >> a[i];
- }
- for(int i = 0; i < m; ++i)
- {
- fin >> b[i];
- }
- cout << "n = " << n << '\n';
- for(int i = 0; i < n; ++i)
- {
- cout << a[i] << " ";
- }
- cout << '\n';
- cout << "m = " << m << '\n';
- for(int i = 0; i < m; ++i)
- {
- cout << b[i] << " ";
- }
- cout << '\n';
- }
- void calc(){
- if(n < m) {
- // a < b poti sa le interschimbi cand le citesti sa fie mereu a mai mic, mie mi-e lene acuma
- int ok = 0;
- int temp, poz = n/2;
- int rasp = 0;
- while(ok == 0 && poz >= 0 && poz < n) {
- temp = a[poz-1];
- cout << "verif poz " << poz << ": " << b[k - poz -1] << " < " << temp << " < " << b[k - poz] << '\n';
- if((b[k - poz -1] <= temp) && (temp < b[k - poz])) {
- ok = 1;
- rasp = temp;
- }
- else
- if(b[k - poz -1] > temp) poz++;
- else if(temp > b[k - poz]) poz--;
- }
- cout << "raspuns = " << rasp;
- }
- }
- int main()
- {
- ctr();
- calc();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement