Գրել ծրագիր, որն էկրանին կտպի
“YES”
, եթե ամբողջ թվերի զանգվածում գոյություն ունեն 2 թիվ, որոնց գումարը հավասար է տրված sum
թվին, հակառակ դեպքում` “NO”
։Օրինակներ`
Մուտք -
[0, -1, 2, -3, 1], x = -2։
Ծրագիրը կտպի “YES”
, քանի որ (-3) + 1 = -2
։Մուտք -
[1, -2, 1, 0, 5], x = 0։
Ծրագիրը կտպի “YES”
, քանի որ 1 + (-1) = 0
#include <iostream> #include <vector> bool checkSum(const std::vector<int>& a, int sum) { // put your code here } int main() { std::vector<int> arr; int size; std::cout << "Insert vector size "; std::cin >> size; std::cout << size << std::endl; std::cout << "Insert vector elements: "; for (int i = 0; i < size; ++i) { int in; std::cin >> in; std::cout << in << " "; arr.push_back(in); } std::cout << std::endl; int x = 0; std::cout << "Insert target sum "; std::cin >> x; std::cout << x << std::endl; // put your code here }