Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C++ code to find palindrome string whose substring is S
Suppose we have a string S with n letters. We have to find another string T, such that T is palindrome and S is subsequence of T.
So, if the input is like S = "ab", then the output will be "aabaa" (other answers are also available)
Steps
To solve this, we will follow these steps −
res := S reverse the array S res := res + S return res
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h>
using namespace std;
string solve(string S){
string res = S;
reverse(S.begin(), S.end());
res += S;
return res;
}
int main(){
string S = "ab";
cout << solve(S) << endl;
}
Input
ab
Output
abba
Advertisements
