C#实现:给定任意要给字符串,输出所有可能的回文的子字符串集合。
class Program
{
static void Main(string[] args)
{
string testStr = "sdfadfdsfadfdsfsdf";
int length = testStr.Length;
while (length > )
{ getPalindrome(testStr.Substring(, length - ), testStr.Substring(length - ), new List<string>()); --length;
} Console.ReadKey();
} /// <summary>
///
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
static void getPalindrome(string subLeft, string subRight, List<string> leftPalindromeStr)
{ int length = subRight.Length;
List<string> palindromeStrs = leftPalindromeStr; if (isPalindrome(subLeft) == true)
{
palindromeStrs.Add(subLeft);
if (isPalindrome(subRight))
{
Console.WriteLine("{0},{1}", String.Join(",", palindromeStrs), subRight);
} while (length > )
{
List<string> ss = new List<string>();
ss.AddRange(palindromeStrs);
getPalindrome(subRight.Substring(, length - ), subRight.Substring(length - ), ss);
length--;
}
}
} static bool isPalindrome(string str)
{
int length = str.Length;
int half = length / ; for (int i = ; i < half; i++)
{
if (str[i] != str[length - i - ])
{
return false;
}
} return true;
}
}
C#实现:给定任意要给字符串,输出所有可能的回文的子字符串集合。的更多相关文章
- cf#516C. Oh Those Palindromes(最多回文子串的字符串排列方式,字典序)
http://codeforces.com/contest/1064/problem/C 题意:给出一个字符串,要求重新排列这个字符串,是他的回文子串数量最多并输出这个字符串. 题解:字典序排列的字符 ...
- 【Python】回文palindrome——利用字符串反转
回文 palindrome Python 字符串反转string[::-1] Slice notation "[a : b : c]" means "count in i ...
- python经典算法题:求字符串中最长的回文子串
题目 给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为 1000. 示例 1: 输入: "babad" 输出: "bab" 注意: ...
- Longest Palindromic Substring - 字符串中最长的回文字段
需求:Given a string S, find the longest palindromic substring in S. You may assume that the maximum le ...
- 九度OJ 1252:回文子串 (字符串处理、DP)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:387 解决:224 题目描述: 输入一个字符串,输出该字符串中对称的子字符串的最大长度. 比如输入字符串"google" ...
- 第5题 查找字符串中的最长回文字符串---Manacher算法
转载:https://www.felix021.com/blog/read.php?2040 首先用一个非常巧妙的方式,将所有可能的奇数/偶数长度的回文子串都转换成了奇数长度:在每个字符的两边都插入一 ...
- c++ 获取字符串中最长的回文子串
#include <vector> #include <iostream> #include <string> using namespace std; strin ...
- 647. Palindromic Substrings 互文的子字符串
[抄题]: Given a string, your task is to count how many palindromic substrings in this string. The subs ...
- C语音输出前100个回文素数,每行10个,适当对齐
#include<stdio.h> #include<math.h> int ss(long n) { ); ) ; ;i<=sqrt(n);i++) ); ; } lo ...
随机推荐
- sql2008r2-vs2013安装下载
vs2013链接:http://www.cnblogs.com/wuyepiaoxue/p/5661174.html sql2008r2链接:http://download.microsoft.com ...
- .NET (上传的)文件下载
string strPath = “//UploadFiles/Equipment/QQ截图.png” // 文件有效地址 FileInfo fileInfo = new FileInfo(strPa ...
- MySQL事件 Events
MySQL事件 Events 一.关键字: EVENT 二.语法: CREATE EVENT? [IF NOT EXISTS ] //如果不存在则创建 event_name? ON SCHED ...
- Windows下Eclipse+Scala+Spark开发环境搭建
1.安装JDK及配置java环境变量 本文使用版本为jdk1.7.0_79,过程略 2.安装scala 本文使用版本为2.11.8,过程略 3.安装spark 本文使用版本为spark-2.0.1-b ...
- python基础知识7——迭代器,生成器,装饰器
迭代器 1.迭代器 迭代器是访问集合元素的一种方式.迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不会后退,不过这也没什么,因为人们很少在迭代途中往后退.另外,迭代器 ...
- c#判断闰年
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- SQL SELECT SET
SELECT SET 同时对多个变量同时赋值时 支持 不支持 表达式返回多个值时 将返回的最后一个值赋给变量 出错 表达式未返回值时 变量保持原值 变量被赋null值
- Android_Activity生命周期
通过前面一段时间的学习,我们很清楚我们的一系列操作都离不开的一个东西,就是我们的activity .接下来我们对 Activity 进行系统的总结. Activity 的四种基本状态 1.运行态(Ru ...
- iOS 当请求到的数据是double类型,会失去精准度,并且去掉小数点后的0
首先请求到的数据都会变成字符串,先将字符串转化为double类型 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: ...
- sql时间查询的问题
今天在做一个时间查询的时候遇到一个问题,就是获取的时间是 数据库的存储是这样的2016-10-29 12:11:40 2016-10-31 15:00:05 ... $log=M('table' ...