国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#查找字符串所有排列組合的方法

2020-01-24 01:54:49
字體:
來源:轉載
供稿:網友

本文實例講述了C#查找字符串所有排列組合的方法。分享給大家供大家參考。具體實現方法如下:

// 1. remove first char // 2. find permutations of the rest of chars// 3. Attach the first char to each of those permutations.// 3.1 for each permutation, move firstChar in all indexes //   to produce even more permutations.// 4. Return list of possible permutations.public string[] FindPermutations(string word){ if (word.Length == 2) {  char[] _c = word.ToCharArray();  string s = new string(new char[] { _c[1], _c[0] });  return new string[]  {   word,   s  }; } List<string> _result = new List<string>(); string[] _subsetPermutations = FindPermutations(word.Substring(1)); char _firstChar = word[0]; foreach (string s in _subsetPermutations) {  string _temp = _firstChar.ToString() + s;  _result.Add(_temp);  char[] _chars = _temp.ToCharArray();  for (int i = 0; i < _temp.Length - 1; i++)  {   char t = _chars[i];   _chars[i] = _chars[i + 1];   _chars[i + 1] = t;   string s2 = new string(_chars);   _result.Add(s2);  } } return _result.ToArray();}

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 林口县| 沙田区| 阿勒泰市| 麻城市| 当雄县| 额尔古纳市| 阿勒泰市| 汾西县| 迁安市| 二连浩特市| 景东| 云南省| 马尔康县| 宜春市| 铜川市| 文登市| 高碑店市| 万州区| 富蕴县| 丰城市| 讷河市| 江油市| 邵阳县| 北碚区| 会泽县| 姜堰市| 天台县| 涟水县| 靖边县| 鲁甸县| 华宁县| 灌云县| 琼结县| 全椒县| 临湘市| 梓潼县| 鹰潭市| 惠安县| 扎鲁特旗| 中宁县| 广安市|