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#实现:给定任意要给字符串,输出所有可能的回文的子字符串集合。的更多相关文章

  1. cf#516C. Oh Those Palindromes(最多回文子串的字符串排列方式,字典序)

    http://codeforces.com/contest/1064/problem/C 题意:给出一个字符串,要求重新排列这个字符串,是他的回文子串数量最多并输出这个字符串. 题解:字典序排列的字符 ...

  2. 【Python】回文palindrome——利用字符串反转

    回文 palindrome Python 字符串反转string[::-1] Slice notation "[a : b : c]" means "count in i ...

  3. python经典算法题:求字符串中最长的回文子串

    题目 给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为 1000. 示例 1: 输入: "babad" 输出: "bab" 注意: ...

  4. Longest Palindromic Substring - 字符串中最长的回文字段

    需求:Given a string S, find the longest palindromic substring in S. You may assume that the maximum le ...

  5. 九度OJ 1252:回文子串 (字符串处理、DP)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:387 解决:224 题目描述: 输入一个字符串,输出该字符串中对称的子字符串的最大长度. 比如输入字符串"google" ...

  6. 第5题 查找字符串中的最长回文字符串---Manacher算法

    转载:https://www.felix021.com/blog/read.php?2040 首先用一个非常巧妙的方式,将所有可能的奇数/偶数长度的回文子串都转换成了奇数长度:在每个字符的两边都插入一 ...

  7. c++ 获取字符串中最长的回文子串

    #include <vector> #include <iostream> #include <string> using namespace std; strin ...

  8. 647. Palindromic Substrings 互文的子字符串

    [抄题]: Given a string, your task is to count how many palindromic substrings in this string. The subs ...

  9. C语音输出前100个回文素数,每行10个,适当对齐

    #include<stdio.h> #include<math.h> int ss(long n) { ); ) ; ;i<=sqrt(n);i++) ); ; } lo ...

随机推荐

  1. PHP集成百度Ueditor 1.4.3

    下载安装 1.首先到官网下载最新版的UE1.4.3UE官方下载地址:http://ueditor.baidu.com/website/download.html#ueditor 这里我下载的是1.4. ...

  2. cocos2d-js callFunc传参

    1.传递一个参数: pg.TestScene.prototype.init = function () { if (cc.Scene.prototype.init.call(this)) { var ...

  3. HDOJ(1348)二维凸包

    Wall http://acm.hdu.edu.cn/showproblem.php?pid=1348 题目描述:有个国王想在他的城堡外面修围墙,围墙与城堡的最小距离为L,要求围墙长度最短.求围墙的长 ...

  4. prolog 规则

    规则 规则由几个互相依赖的简单句(谓词)组成.用来描述事实之间的依赖关系,如:因果关系,蕴含关系,对应关系 规则的实质就是存储起来得查询 其语法结构如下: head:-body head 为谓词的定义 ...

  5. 9.8 js进阶总结3

    DOM文档对象模型 DOM(document object model)文档对象模型,它定义了操作文档对象的接口. DOM 把一份html文档表示为一棵家谱树,使用parent(父),child(子) ...

  6. springmvc spring mybatis插入mysql中文乱码

    springmvc 插入mysql数据库中文乱码问题: 1.将页面中的编码改成utf-8 2.用SQLyog右击->改变数据库 以上两步可以保证页面数据编码一致 3.在mybatis连接的地方加 ...

  7. c++ 11 sleep()

    #include<chrono>#include<thread> std::this_thread::sleep_for(std::chrono::milliseconds(1 ...

  8. Android 工程师如何快速学会web前段

    Android 工程师如何快速学会web前段 今天主要聊一下本人最近在学习web前段的感受,最近html5是越来越火了,前段时间公司做了一个项目然后让我们“android”的程序猿过去帮忙把客户 端框 ...

  9. TextView实现歌词同步

    利用TextView实现歌词同步显示,这是一个简单的利用TextView实现滚动实时显示歌词的. 里面的内容都已经写上了详细的注释.里面播放音乐的时候歌词同步展示. 做媒体这块的朋友可以学习一下,练练 ...

  10. 【简易版】Java ArrayList(增删改查)

    1.什么是ArrayList ArrayList就是传说中的动态数组,用MSDN中的说法,就是Array的复杂版本,它提供了如下一些好处: (1)动态的增加和减少元素 (2)实现了ICollectio ...