fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. bool isPalindrome(string str, int len){
  7.  
  8. int l = 0;
  9. int h = len - 1;
  10.  
  11. while(h > l){
  12.  
  13. if(str[l++] != str[h--])
  14. return false;
  15. }
  16. return true;
  17.  
  18. }
  19.  
  20. int main() {
  21. vector<string> randomStrings;
  22.  
  23. randomStrings.push_back("ABA");
  24. randomStrings.push_back("AAB");
  25. randomStrings.push_back("Good");
  26.  
  27.  
  28. for(int i = 0; i < randomStrings.size(); i++){
  29.  
  30. if(isPalindrome(randomStrings[i], randomStrings.size()))
  31. cout<<"The string "<<randomStrings[i]<<" IS a palindrome"<<endl;
  32. else
  33. cout<<"The string "<<randomStrings[i]<<" is NOT a palindrome"<<endl;
  34. }
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 4368KB
stdin
Standard input is empty
stdout
The string ABA IS a palindrome
The string AAB is NOT a palindrome
The string Good is NOT a palindrome