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++ program to find string after adding character 'a' string becomes non-palindrome
Suppose we have a string S with lowercase English letters. We must insert exactly one character 'a' in S. After inserting that if we can make S not a palindrome then return that string, otherwise return "impossible".
So, if the input is like S = "bpapb", then the output will be "bpaapb"
Steps
To solve this, we will follow these steps −
if concatenation of S and "a" is not palindrome, then: return S concatenation 'a' otherwise when concatenation of "a" + S is not palindrome, then: return 'a' concatenation S Otherwise return "Impossible"
Example
Let us see the following implementation to get better understanding −
#includeusing namespace std; bool p(const string& s) { for (int i = 0; i Input
"bpapb"Output
bpapba
Advertisements
