Advertisement
Tannenfels

Untitled

Oct 16th, 2022
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. struct result{
  4.     int nums[2];
  5. };
  6.  
  7.  
  8. result* xseek(int* a, int len, int x)
  9. {
  10.     auto res = new result;
  11.     int* b = a + --len;
  12.     do {
  13.         if((*a + *b) == x) {
  14.             res->nums[0] = *a;
  15.             res->nums[1] = *b;
  16.             return res;
  17.         } else if((*a + *b) < x) {
  18.             a++;
  19.         } else if((*a + *b) > x) {
  20.             b--;
  21.         }
  22.     } while (a != b);
  23.    
  24. }
  25.  
  26. int main()
  27. {
  28.     int arr[5] = {0, 1, 2, 3, 4};
  29.     int* a = arr;
  30.     auto res = xseek(a, 5, 7);
  31.    
  32.     std::cout << res->nums[0] << ',' << res->nums[1] << std::endl;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement