{"id":863,"date":"2012-04-07T20:56:26","date_gmt":"2012-04-07T20:56:26","guid":{"rendered":"http:\/\/41j.com\/blog\/?p=863"},"modified":"2015-03-05T05:28:11","modified_gmt":"2015-03-05T05:28:11","slug":"find-items-in-an-array-that-sum-to-15","status":"publish","type":"post","link":"https:\/\/41j.com\/blog\/2012\/04\/find-items-in-an-array-that-sum-to-15\/","title":{"rendered":"Pairs in an array that sum to 15&#8230;"},"content":{"rendered":"<p>Messy and hacky, should use set rather than map. In reality should use a hash&#8230;<\/p>\n<p>#include <vector><br \/>\n#include <\/p>\n<map>\n<p>using namespace std;<\/p>\n<p>int main() {<\/p>\n<p>  vector<int> array;<\/p>\n<p>  array.push_back(1);<br \/>\n  array.push_back(10);<br \/>\n  array.push_back(5);<\/p>\n<p>  map<int,int> exists;<br \/>\n  for(size_t n=0;n<array.size();n++) {\n    exists[array[n]] = 1;\n  }\n  \n  for(size_t n=0;n<array.size();n++) {\n    int value_needed = 15-array[n];\n    \n    if(exists[value_needed] == 1) cout << \"pair: \" << array[n] << \" \" << value_needed << endl;\n  }\n\n\n}\n[\/sourcecode]\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Messy and hacky, should use set rather than map. In reality should use a hash&#8230; #include #include using namespace std; int main() { vector array; array.push_back(1); array.push_back(10); array.push_back(5); map exists; for(size_t n=0;n<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-863","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1RRoU-dV","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/comments?post=863"}],"version-history":[{"count":3,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/863\/revisions"}],"predecessor-version":[{"id":2182,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/863\/revisions\/2182"}],"wp:attachment":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/media?parent=863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/categories?post=863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/tags?post=863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}