

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
- Related Questions & Answers
- C++ program to find string with palindrome substring whose length is at most k
- C++ code to find string where trygub is not a substring
- C++ code to find composite numbers whose difference is n
- C++ code to find greater number whose factor is k
- C++ code to find three numbers whose sum is n
- C++ program to find length of non empty substring whose sum is even
- MongoDB query to find documents whose array contains a string that is a substring of a specific word
- Palindrome Substring Queries in C++
- C++ code to find two substrings with one minimal substring
- How to find if a string is a palindrome using Java?
- C++ program to find maximum possible median of elements whose sum is s
- JavaScript - Find if string is a palindrome (Check for punctuation)
- Can Make Palindrome from Substring in Python
- Write an example to find whether a given string is palindrome using recursion
- How to check if String is Palindrome using C#?
Advertisements