Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. char s1[10], s2[10];
  7. char s3[10];
  8. int i, n, j = 0, found = 0, k = 0;
  9. int count = 0;
  10. cout << "Please input a string: ";
  11. cin >> s1;
  12. strcpy_s(s2, s1); /*s2=initial, s1=flipped*/
  13. n = strlen(s1) - 1;
  14. for (i = 0; i < n; i++, n--) /*flipping*/
  15. {
  16. char temp = s1[i];
  17. s1[i] = s1[n];
  18. s1[n] = temp;
  19. }
  20. n = strlen(s1) - 1;
  21. i = 0;
  22. while (i <= n) {
  23. if (s1[i] == s2[i] && s1[i + 1] == s2[i + 1])
  24. {
  25. found += 1;
  26. s3[j] = s2[i];
  27. s3[j + 1] = s2[i + 1];
  28. j += 2;
  29. i += 2;
  30. }
  31. else
  32. i += 1;
  33. }
  34.  
  35. if (found == 0) {
  36. cout << "There is no palindromic substring";
  37. }
  38. else {
  39. cout << "The result is: " << s3;
  40. }
  41. cin >> i;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement