查找Palindrome字符串的C++代码,其子字符串为S
假设我们有一个包含n个字母的字符串S。我们必须找出另一个字符串T,使得T是回文串且S是T的子序列。
因此,如果输入是S="ab",则输出将是"aabaa"(还有其他答案可用)
步骤
要解决这个问题,我们将遵循以下步骤-
res := S reverse the array S res := res + S return res
示例
让我们看看以下实现,以便更好地理解-
#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;
}输入
ab
输出
abba
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C编程
C++
C#
MongoDB
MySQL
Javascript
PHP