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 ...
 
随机推荐
- js数组中去除重复对象及去除空对象的方法
			
(function(){//去除数组中重复对象 var unique = {}; arr.forEach(function(a){ unique[ JSON.stringify(a) ] = 1 }) ...
 - Android之官方下拉刷新控件SwipeRefreshLayout
			
SwipeRefreshLayout 是在V4包里面,首先要先导入V4包,最新的V4包里面才有这控件 首先是布局 <android.support.v4.widget.SwipeRefreshL ...
 - 如何让table中td宽度固定
			
table中td会随着里面的内容伸缩,设置其width样式并没有效果.这个时候需要下面的CSS可以实现. 首先是设置table .table {table-layout:fixed;} 其次是td . ...
 - UVa 694 - The Collatz Sequence
			
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=s ...
 - C6000系类的内联函数
			
1.求绝对值函数 (1) _abs() C代码 : int _abs(int src) 汇编: ABS 功能: 求32位数据的绝对值 (2) _labs() C代码: int _labs ...
 - win8 系统无法正常安装.net framework 2.0和3.0框架如何解决
			
在安装.net framework2.0框架的时候一直提示要用户从网上面下载框架,你点击下载好的安装包也是无法安装的.这个时候就需要你使用离线的安装包来进行问题的解答附件在此http://pan.ba ...
 - eclipse导出jar包的方法
			
第一:导出基本项目的jar包(此项目没有引用过第三方jar包) 1.在eclipse中选择你要导出的项目或package或类,右击,选择Export子选项: 2.在弹出的对话框中,选择java文件-- ...
 - ffmpeg总结整理
			
ffmpeg总结整理参考链接: http://www.cnblogs.com/youngt/p/5754415.html
 - 通过系统自带的内容提供器(ContentResolver)读取系统的通讯录,并设置点击事件
			
1.布局 主布局只有一个listview,用来显示电话簿的名字和手机号码 <?xml version="1.0" encoding="utf-8"?> ...
 - 用任意语言与WebService进行交互
			
using System; using System.Web.Services; using YY.SmsPlatform.Common.Objects; using YY.SmsPlatform.C ...