fork download
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. bool ispalindrome(char* s, int l, int r)
  6. {
  7. int n = r-l+1;
  8. for(int i=0; i<n/2; i++)
  9. {
  10. if(s[l+i] != s[r-i])
  11. return false;
  12. }
  13.  
  14. for(int i=l; i<=r; i++)
  15. cout << s[i];
  16. cout << endl;
  17. return true;
  18. }
  19. void palindromesubstrings(char* s)
  20. {
  21. int n = strlen(s);
  22. for(int i=0; i<n; i++)
  23. {
  24. for(int j=i+1; j<n; j++)
  25. {
  26. if(s[i] == s[j])
  27. {
  28. //cout << "[" << i << "," << j << "]=" << s[i] << endl;
  29. ispalindrome(s,i,j);
  30. }
  31. }
  32. }
  33. }
  34.  
  35. int main() {
  36. // your code goes here
  37. char s1[100], s2[100];
  38. cin >> s1;
  39. cin >> s2;
  40. //cout << "palindrome " << s1 << " " << (ispalindrome(s1,0,strlen(s1)-1)? "true" : "false");
  41. cout << "palindrome substrings of " << s2 << ":\n";
  42. palindromesubstrings(s2);
  43. return 0;
  44. }
Success #stdin #stdout 0s 16064KB
stdin
abba
ABCBAHELLOHOWRACECARAREYOUIAMAIDOINGGOOD
stdout
palindrome substrings of ABCBAHELLOHOWRACECARAREYOUIAMAIDOINGGOOD:
ABCBA
BCB
LL
OHO
RACECAR
ACECA
CEC
ARA
RAR
IAMAI
AMA
GG
OO