int main(){ int tar; TwoSum ts; cout<<"please input the numbers!"<<endl; int it = 0; while(true){ int c; cin>>c; ts.add(c, it); it++; char cc = cin.get(); if(cc == '\n') break; } ts.out(); cout<<"please input the target!"<<endl; cin>>tar; vector<int> res = ts.find(tar); for(vector<int>::iterator k = res.begin(); k != res.end(); k ++) cout<< *k<<endl; }
int main() { TwoSum ts; ts.add(1); ts.add(-2); ts.add(3); ts.add(3); ts.add(4); bool rslt = ts.find(2); rslt = ts.find(5); rslt = ts.find(8); rslt = ts.find(6); return 0; }
int main( int argc, char ** argv ) { TwoSum ts; ts.read(argv[1]); std::cout << ts.find_range( atoi(argv[2]), atoi(argv[3]) ) << std::endl; };
#include "catch.hpp" #include "TwoSum.hpp" TEST_CASE("Two Sum") { TwoSum s; SECTION("Sample test") { vector<int> numbers{2, 7, 11, 15}; int target = 9; vector<int> ans{0, 1}; REQUIRE(s.twoSum(numbers, target) == ans); } SECTION("Have duplicate elements and the answer relies on duplicate elements") { vector<int> numbers{3, 3, 4}; int target = 6; vector<int> ans{0, 1}; REQUIRE(s.twoSum(numbers, target) == ans); } SECTION("Have duplicate elements and the answer doesn't rely on duplicate elements") { vector<int> numbers{3, 3, 4, 1}; int target = 5; vector<int> ans{2, 3}; REQUIRE(s.twoSum(numbers, target) == ans); } }