{"id":856,"date":"2012-04-07T01:32:15","date_gmt":"2012-04-07T01:32:15","guid":{"rendered":"http:\/\/41j.com\/blog\/?p=856"},"modified":"2012-04-06T01:33:18","modified_gmt":"2012-04-06T01:33:18","slug":"check-if-string-palindrome","status":"publish","type":"post","link":"https:\/\/41j.com\/blog\/2012\/04\/check-if-string-palindrome\/","title":{"rendered":"Check if string palindrome"},"content":{"rendered":"<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\n#include &lt;string&gt;\r\n\r\nusing namespace std;\r\n\r\n\r\nbool check(string palendrome) {\r\n\r\n  size_t limit=0;\r\n  if(palendrome.size()%2 == 0) limit = palendrome.size()\/2;\r\n                          else limit = (palendrome.size()-1)\/2;\r\n\r\n  for(size_t n=0;n&lt;limit;n++) {\r\n    if(palendrome&#x5B;n] != palendrome&#x5B;palendrome.size()-n-1]) return false;\r\n  }\r\n  return true;\r\n}\r\n\r\nint main() {\r\n\r\n  string palendrome1 = &quot;catac&quot;;\r\n  bool check1 = check(palendrome1); if(check1 == true) cout &lt;&lt; palendrome1 &lt;&lt; &quot; is palendromic&quot; &lt;&lt; endl; else cout &lt;&lt; palendrome1 &lt;&lt; &quot; is not palendromic&quot; &lt;&lt; endl;\r\n\r\n  string palendrome2 = &quot;caac&quot;;\r\n  bool check2 = check(palendrome2); if(check2 == true) cout &lt;&lt; palendrome2 &lt;&lt; &quot; is palendromic&quot; &lt;&lt; endl; else cout &lt;&lt; palendrome2 &lt;&lt; &quot; is not palendromic&quot; &lt;&lt; endl;\r\n\r\n  string palendrome3 = &quot;zcaacr&quot;;\r\n  bool check3 = check(palendrome3); if(check3 == true) cout &lt;&lt; palendrome3 &lt;&lt; &quot; is palendromic&quot; &lt;&lt; endl; else cout &lt;&lt; palendrome3 &lt;&lt; &quot; is not palendromic&quot; &lt;&lt; endl;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#include &lt;iostream&gt; #include &lt;string&gt; using namespace std; bool check(string palendrome) { size_t limit=0; if(palendrome.size()%2 == 0) limit = palendrome.size()\/2; else limit = (palendrome.size()-1)\/2; for(size_t n=0;n&lt;limit;n++) { if(palendrome&#x5B;n] != palendrome&#x5B;palendrome.size()-n-1]) return false; } return true; } int main() { string palendrome1 = &quot;catac&quot;; bool check1 = check(palendrome1); if(check1 == true) cout &lt;&lt; palendrome1 &lt;&lt; &quot; is [&hellip;]<\/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-856","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1RRoU-dO","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/856","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=856"}],"version-history":[{"count":1,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/856\/revisions"}],"predecessor-version":[{"id":857,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/856\/revisions\/857"}],"wp:attachment":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/media?parent=856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/categories?post=856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/tags?post=856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}