Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- int main() {
- char s1[10], s2[10];
- char s3[10];
- int i, n, j = 0, found = 0, k = 0;
- int count = 0;
- cout << "Please input a string: ";
- cin >> s1;
- strcpy_s(s2, s1); /*s2=initial, s1=flipped*/
- n = strlen(s1) - 1;
- for (i = 0; i < n; i++, n--) /*flipping*/
- {
- char temp = s1[i];
- s1[i] = s1[n];
- s1[n] = temp;
- }
- n = strlen(s1) - 1;
- i = 0;
- while (i <= n) {
- if (s1[i] == s2[i] && s1[i + 1] == s2[i + 1])
- {
- found += 1;
- s3[j] = s2[i];
- s3[j + 1] = s2[i + 1];
- j += 2;
- i += 2;
- }
- else
- i += 1;
- }
- if (found == 0) {
- cout << "There is no palindromic substring";
- }
- else {
- cout << "The result is: " << s3;
- }
- cin >> i;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement