35657

Untitled

Sep 28th, 2024
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.  
  10.  
  11.     ifstream fin("input.txt");
  12.  
  13.     int count, number;
  14.     fin >> count; // количество чисел
  15.  
  16.     vector<int> vec(count);
  17.  
  18.     for (size_t i = 0; i < count; i++) {
  19.         fin >> vec[i];
  20.     }
  21.  
  22.     fin >> number; // загаданное число
  23.  
  24.     int current_sum;
  25.  
  26.     size_t left = 0, right = count - 1;
  27.     while (left < right) {
  28.         current_sum = vec[left] + vec[right];
  29.         if (current_sum == number) {
  30.             cout << vec[left] << " " << vec[right] << endl;
  31.             return 0;
  32.         }
  33.         current_sum < number ? left++ : right--;
  34.     }
  35.     cout << "None" << endl;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment